AWS Lambda模板看不到我自己的存储桶

时间:2018-10-30 17:16:27

标签: amazon-web-services amazon-s3 aws-lambda

我正在遵循此guide来部署我的Lambda。该解决方案使用他们自己的.template文件进行部署。但是,我需要对该Lambda进行一些代码更改,因此我将更改后的Lambda代码上传到我自己的存储桶中,并更改了.template以与我自己的存储桶一起使用。

原始模板

CustomResource:
      S3Bucket: solutions
      S3Key: >-
        serverless-image-handler/v3.0.0/serverless-image-handler-custom-resource.zip
      Name: serverless-image-handler-custom-resource
      Handler: image_handler_custom_resource/cfn_custom_resource.lambda_handler
      Description: >-
        Serverless Image Handler: CloudFormation custom resource function
        invoked during CloudFormation create, update, and delete stack
        operations.
      Runtime: python2.7
      Timeout: '60'
      MemorySize: '128'

我的自定义模板(使用我的存储桶)

CustomResource:
      S3Bucket: my-bucket
      S3Key: >-
        serverless-image-handler/serverless-image-handler-custom-resource.zip
      Name: serverless-image-handler-custom-resource
      Handler: image_handler_custom_resource/cfn_custom_resource.lambda_handler
      Description: >-
        Serverless Image Handler: CloudFormation custom resource function
        invoked during CloudFormation create, update, and delete stack
        operations.
      Runtime: python2.7
      Timeout: '60'
      MemorySize: '128'

当然,在我的存储桶中,我将包装放在正确的路径serverless-image-handler/serverless-image-handler-custom-resource.zip下。但是,当尝试部署时,出现以下错误。

Error occurred while GetObject. S3 Error Code: NoSuchBucket. S3 Error Message: The specified bucket does not exist (Service: AWSLambda; Status Code: 400; Error Code: InvalidParameterValueException; Request ID: 6b666b56-dc62-11e8-acb0-8df0d82e071b)

就好像它无法“看到”我自己的存储桶,但看到的是存储桶solutions。如何让它看到我的水桶?

编辑

定义存储桶的模板的一部分。

Parameters:
  OriginS3Bucket:
    Description: S3 bucket that will source your images.
    Default: original-images-bucket-name
    Type: String
    ConstraintDescription: Must be a valid S3 Bucket.
    MinLength: '1'
    MaxLength: '64'
    AllowedPattern: '[a-zA-Z][a-zA-Z0-9-.]*'
  OriginS3BucketRegion:
    Description: S3 bucket Region that will source your images.
    Default: eu-central-1
    Type: String
    AllowedValues:
      - ap-south-1
      - ap-northeast-1
      - ap-northeast-2
      - ap-southeast-1
      - ap-southeast-2
      - ca-central-1
      - eu-central-1
      - eu-west-1
      - eu-west-2
      - eu-west-3
      - sa-east-1
      - us-east-1
      - us-east-2
      - us-west-1
      - us-west-2

模板的一部分抛出了错误。

CustomResource:
    Type: 'AWS::Lambda::Function'
    DependsOn:
      - CustomResourceLoggingPolicy
      - CustomResourceDeployPolicy
    Properties:
      Code:
        S3Bucket: !Join
          - ''
          - - !FindInMap
              - Function
              - CustomResource
              - S3Bucket
            - '-'
            - !Ref 'AWS::Region'
        S3Key: !FindInMap
          - Function
          - CustomResource
          - S3Key
      MemorySize: !FindInMap
        - Function
        - CustomResource
        - MemorySize
      Handler: !FindInMap
        - Function
        - CustomResource
        - Handler
      Role: !GetAtt
        - CustomResourceRole
        - Arn
      Timeout: !FindInMap
        - Function
        - CustomResource
        - Timeout
      Runtime: !FindInMap
        - Function
        - CustomResource
        - Runtime
      Description: !FindInMap
        - Function
        - CustomResource
        - Description
      Environment:
        Variables:
          LOG_LEVEL: INFO

0 个答案:

没有答案