お世話になります。
lambda functionを用いてec2のAMIのbackupを定期的に取得する方法を作成しています。
参考にしたサイトは以下になります。
https://qiita.com/tonishy/items/74e145f8c9cba031fa01
参考サイトに従う形でのlambda function作成は成功しました。
次のステップとしてserverless frameworkに環境を落とし込むことを検討しています。
下記のserverless.ymlでdeployするとsuccessはしています。
service: ec2-backup-new provider: name: aws runtime: python3.6 region: ap-northeast-1 role: arn:aws:iam::XXXXXXXXXXXX:role/ec2-backup-test functions: ec2-image-backup: handler: ec2-image-backup.lambda_handler environment: AWS_ACCOUNT: 'XXXXXXXXXXXX' # AWSアカウントを記述 events: - schedule: cron(0 9 * * ? *) #バックアップを実行したい時間をcron式で記述 delete_snapshot_after_ami_deregister: handler: delete_snapshot_after_ami_deregister.lambda_handler environment: AWS_ACCOUNT: 'XXXXXXXXXXXX' # AWSアカウントを記述 events: - cloudwatchEvent: enabled: true event: source: - "aws.ec2" detail-type: - "AWS API Call via CloudTrail" detail: eventSource: - "ec2.amazonaws.com" eventName: - "DeregisterImage"
しかし、以下の部分だけのAWSが作成されません。
cloudformationのログを見てもこのリソースに関する出力は無いようです。
events: - cloudwatchEvent: enabled: true event: source: - "aws.ec2" detail-type: - "AWS API Call via CloudTrail" detail: eventSource: - "ec2.amazonaws.com" eventName: - "DeregisterImage"
sls deploy時のターミナルのログです。
mac11:ec2-backup-new $ sls deploy --verbose (node:99826) ExperimentalWarning: The fs.promises API is experimental Serverless: Packaging service... Serverless: Excluding development dependencies... Serverless: Creating Stack... Serverless: Checking Stack create progress... CloudFormation - CREATE_IN_PROGRESS - AWS::CloudFormation::Stack - ec2-backup-new-dev CloudFormation - CREATE_IN_PROGRESS - AWS::S3::Bucket - ServerlessDeploymentBucket CloudFormation - CREATE_IN_PROGRESS - AWS::S3::Bucket - ServerlessDeploymentBucket CloudFormation - CREATE_COMPLETE - AWS::S3::Bucket - ServerlessDeploymentBucket CloudFormation - CREATE_COMPLETE - AWS::CloudFormation::Stack - ec2-backup-new-dev Serverless: Stack create finished... Serverless: Uploading CloudFormation file to S3... Serverless: Uploading artifacts... Serverless: Uploading service .zip file to S3 (4.87 KB)... Serverless: Validating template... Serverless: Updating Stack... Serverless: Checking Stack update progress... CloudFormation - CREATE_COMPLETE - AWS::CloudFormation::Stack - ec2-backup-new-dev CloudFormation - UPDATE_IN_PROGRESS - AWS::CloudFormation::Stack - ec2-backup-new-dev CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - Ec2DashimageDashbackupLogGroup CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - DeleteUnderscoresnapshotUnderscoreafterUnderscoreamiUnderscorederegisterLogGroup CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - Ec2DashimageDashbackupLogGroup CloudFormation - CREATE_COMPLETE - AWS::Logs::LogGroup - Ec2DashimageDashbackupLogGroup CloudFormation - CREATE_IN_PROGRESS - AWS::Logs::LogGroup - DeleteUnderscoresnapshotUnderscoreafterUnderscoreamiUnderscorederegisterLogGroup CloudFormation - CREATE_COMPLETE - AWS::Logs::LogGroup - DeleteUnderscoresnapshotUnderscoreafterUnderscoreamiUnderscorederegisterLogGroup CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Function - Ec2DashimageDashbackupLambdaFunction CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Function - DeleteUnderscoresnapshotUnderscoreafterUnderscoreamiUnderscorederegisterLambdaFunction CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Function - Ec2DashimageDashbackupLambdaFunction CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Function - DeleteUnderscoresnapshotUnderscoreafterUnderscoreamiUnderscorederegisterLambdaFunction CloudFormation - CREATE_COMPLETE - AWS::Lambda::Function - Ec2DashimageDashbackupLambdaFunction CloudFormation - CREATE_COMPLETE - AWS::Lambda::Function - DeleteUnderscoresnapshotUnderscoreafterUnderscoreamiUnderscorederegisterLambdaFunction CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Version - DeleteUnderscoresnapshotUnderscoreafterUnderscoreamiUnderscorederegisterLambdaVersionF86v48XmogxGwz13oRdeqOOXvatKQma1lOtaKDnRtw CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Version - Ec2DashimageDashbackupLambdaVersionGTVn9UWPxL2FHKuc0jSf9SmjwXxvx584Bql3nYbEyM CloudFormation - CREATE_IN_PROGRESS - AWS::Events::Rule - Ec2DashimageDashbackupEventsRuleSchedule1 CloudFormation - CREATE_IN_PROGRESS - AWS::Events::Rule - Ec2DashimageDashbackupEventsRuleSchedule1 CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Version - DeleteUnderscoresnapshotUnderscoreafterUnderscoreamiUnderscorederegisterLambdaVersionF86v48XmogxGwz13oRdeqOOXvatKQma1lOtaKDnRtw CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Version - Ec2DashimageDashbackupLambdaVersionGTVn9UWPxL2FHKuc0jSf9SmjwXxvx584Bql3nYbEyM CloudFormation - CREATE_COMPLETE - AWS::Lambda::Version - DeleteUnderscoresnapshotUnderscoreafterUnderscoreamiUnderscorederegisterLambdaVersionF86v48XmogxGwz13oRdeqOOXvatKQma1lOtaKDnRtw CloudFormation - CREATE_COMPLETE - AWS::Lambda::Version - Ec2DashimageDashbackupLambdaVersionGTVn9UWPxL2FHKuc0jSf9SmjwXxvx584Bql3nYbEyM CloudFormation - CREATE_COMPLETE - AWS::Events::Rule - Ec2DashimageDashbackupEventsRuleSchedule1 CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Permission - Ec2DashimageDashbackupLambdaPermissionEventsRuleSchedule1 CloudFormation - CREATE_IN_PROGRESS - AWS::Lambda::Permission - Ec2DashimageDashbackupLambdaPermissionEventsRuleSchedule1 CloudFormation - CREATE_COMPLETE - AWS::Lambda::Permission - Ec2DashimageDashbackupLambdaPermissionEventsRuleSchedule1 CloudFormation - UPDATE_COMPLETE_CLEANUP_IN_PROGRESS - AWS::CloudFormation::Stack - ec2-backup-new-dev CloudFormation - UPDATE_COMPLETE - AWS::CloudFormation::Stack - ec2-backup-new-dev Serverless: Stack update finished... Service Information service: ec2-backup-new stage: dev region: ap-northeast-1 stack: ec2-backup-new-dev api keys: None endpoints: None functions: ec2-image-backup: ec2-backup-new-dev-ec2-image-backup delete_snapshot_after_ami_deregister: ec2-backup-new-dev-delete_snapshot_after_ami_deregister Stack Outputs DeleteUnderscoresnapshotUnderscoreafterUnderscoreamiUnderscorederegisterLambdaFunctionQualifiedArn: arn:aws:lambda:ap-northeast-1:XXXXXXXXXXXX:function:ec2-backup-new-dev-delete_snapshot_after_ami_deregister:7 Ec2DashimageDashbackupLambdaFunctionQualifiedArn: arn:aws:lambda:ap-northeast-1:XXXXXXXXXXXX:function:ec2-backup-new-dev-ec2-image-backup:8 ServerlessDeploymentBucketName: ec2-backup-new-dev-serverlessdeploymentbucket-1czl9svgqonuv
serverless.ymlの記述が悪いのでしょうか。
お分かりになる方、アドバイスを頂けましたら幸いです。
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。