3

我正在学习 AWS 无服务器应用程序模型。我正在尝试以下模型:

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Resources:
  MyLambdaFunction:
    Type: 'AWS::Serverless::Function'
    Properties:
      Runtime: nodejs8.10
      Handler: index.handler
      CodeUri: 
        Bucket: artifacts-for-lambda
        Key: my-lambda-package.zip
      Events:
        MySchedule:
          Type: Schedule
          Properties:
            Schedule: rate(1 minute)
        MyS3Upload:
          Type: S3
          Properties:
            Bucket: !Ref MyS3Bucket
            Events: s3:ObjectCreated:*
  MyS3Bucket:
    Type: 'AWS::S3::Bucket'
    Properties:
      BucketName: upload-something-here

这就是我运行它的方式:

aws cloudformation deploy 
--capabilities CAPABILITY_NAMED_IAM 
--template-file sam-template.yaml 
--stack-name my-serverless-app

这是我收到的错误:

GetObject 时发生错误。S3 错误代码:永久重定向。S3 错误消息:存储桶位于此区域:us-east-1。请使用此区域重试请求(服务:AWSLambdaInternal;状态代码:400;错误代码:InvalidParameterValueException

us-east-2是我的 AWS 配置文件的默认区域。

如果us-east-2是我的默认区域,为什么我会收到此错误消息The bucket is in this region: us-east-1?如何在无服务器脚本中为 S3 存储桶指定区域?

4

1 回答 1

2

Tom,我在我正在进行的一个项目中使用了 SAM。你可以像这样使用它:

sam package --template-file template.yml \
              --output-template-file packaged.yml \
              --s3-bucket developing-sam-applications 
              --region YOUR_REGION

此外,您可以在指定区域的情况下使用此命令进行部署:

sam deploy --template-file packaged.yml \
             --stack-name developing-sam-applications \
             --capabilities CAPABILITY_IAM
             --region YOUR_REGION

注意:请确保您在同一区域中拥有存储桶和函数。如果要部署在不同的区域,则需要该区域的存储桶。

于 2019-09-16T14:25:37.173 回答