AWS SAM 部署

时间:2021-07-16 09:30:24

标签: node.js amazon-web-services aws-sam aws-sam-cli

使用时

sam build && sam deploy --guided --capabilities CAPABILITY_IAM

为了部署我的图像压缩 lambda,我收到以下输出:

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
ResourceStatus                                                                                           ResourceType                                                                                             LogicalResourceId                                                                                        ResourceStatusReason                                                                                   
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
CREATE_IN_PROGRESS                                                                                       AWS::IAM::Role                                                                                           ImageCompressionLambdaRole                                                                               Resource creation Initiated                                                                            
CREATE_IN_PROGRESS                                                                                       AWS::IAM::Role                                                                                           ImageCompressionLambdaRole                                                                               -                                                                                                      
CREATE_IN_PROGRESS                                                                                       AWS::S3::Bucket                                                                                          CompressedBucket                                                                                         -                                                                                                      
CREATE_FAILED                                                                                            AWS::IAM::Role                                                                                           ImageCompressionLambdaRole                                                                               Resource creation cancelled                                                                            
CREATE_FAILED                                                                                            AWS::S3::Bucket                                                                                          CompressedBucket                                                                                         regiolix-dev-compressed already exists                                                                 
ROLLBACK_IN_PROGRESS                                                                                     AWS::CloudFormation::Stack                                                                               regiolix-img-compression                                                                                 The following resource(s) failed to create: [ImageCompressionLambdaRole, CompressedBucket]. Rollback   
                                                                                                                                                                                                                                                                                                                           requested by user.                                                                                     
DELETE_IN_PROGRESS                                                                                       AWS::IAM::Role                                                                                           ImageCompressionLambdaRole                                                                               -                                                                                                      
DELETE_COMPLETE                                                                                          AWS::S3::Bucket                                                                                          CompressedBucket                                                                                         -                                                                                                      
DELETE_COMPLETE                                                                                          AWS::IAM::Role                                                                                           ImageCompressionLambdaRole                                                                               -                                                                                                      
ROLLBACK_COMPLETE                                                                                        AWS::CloudFormation::Stack                                                                               regiolix-img-compression                                                                                 -                                                                                                      
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

模板.yml

# This is the SAM template that represents the architecture of your serverless application
# https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-template-basics.html

# The AWSTemplateFormatVersion identifies the capabilities of the template
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/format-version-structure.html
AWSTemplateFormatVersion: 2010-09-09
Description: >-
  image-compression

# Transform section specifies one or more macros that AWS CloudFormation uses to process your template
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-section-structure.html
Transform:
- AWS::Serverless-2016-10-31

Parameters:
  UncompressedBucketName:
    Type: String
    Description: "Input Bucket / Source Bucket"
  CompressedBucketName:
    Type: String
    Description: "Output Bucket / Destination Bucket"

# Resources declares the AWS resources that you want to include in the stack
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html
Resources:
  UncompressedBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Ref UncompressedBucketName
  CompressedBucket:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Ref CompressedBucketName
  # Each Lambda function is defined by properties:
  # https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction

  # This is a Lambda function config associated with the source code: hello-from-lambda.js
  ImageCompressionLambda:
    Type: AWS::Serverless::Function
    Properties:
      Handler: src/index.handler
      Runtime: nodejs12.x
      MemorySize: 128
      Timeout: 100
      Environment:
        Variables:
          UNCOMPRESSED_BUCKET: !Ref UncompressedBucketName
          COMPRESSED_BUCKET: !Ref CompressedBucketName
      Policies:
        - S3ReadPolicy:
            BucketName: !Ref UncompressedBucketName
        - S3WritePolicy:
            BucketName: !Ref CompressedBucketName
      Events:
        CompressImageEvent:
          Type: S3
          Properties:
            Bucket: !Ref UncompressedBucket
            Events: s3:ObjectCreated:*

我不知道我应该怎么做才能完成这项工作。两个存储桶都已存在。当我从 template.yml 中的 Resource 条目中删除它们时,部署失败并显示错误,告诉我为提供的事件引用 Resources 中的存储桶。

有关如何解决此问题的任何想法?

0 个答案:

没有答案