python - sam deploy 失败并出现错误存储桶位于此区域:us-east-2。请将此区域用于 us-east-2
问题描述
我是山姆的新手。
我正在运行 aws-cli/2.1.37 Python/3.8.8 Darwin/19.6.0 exe/x86_64 提示/关闭
SAM CLI,版本 1.29.0
请参阅下面的 template.yaml 文件
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
Trikle
Sample SAM Template for Trikle
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 60
Resources:
PutProfileFunction:
Type: AWS::Serverless::Function # More info about Function Resource: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction
Properties:
FunctionName: PutProfile
Description: Created With SAM Framework adds users profiles
Role: arn:aws:iam::630589988206:role/lambdaAllQueryExecutionAllAccessRole
CodeUri: src/
Handler: add_profile.lambda_handler
Runtime: python3.7
Events:
PutProfile:
Type: Api # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Path: /PutProfile
Method: post
Outputs:
# ServerlessRestApi is an implicit API created out of Events key under Serverless::Function
# Find out more about other implicit resources you can reference within SAM
# https://github.com/awslabs/serverless-application-model/blob/master/docs/internals/generated_resources.rst#api
PutProfileApi:
Description: "API Gateway endpoint URL for Prod stage for PutProfile function"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/dev/PutProfile/"
PutProfileFunction:
Description: "Created With SAM Framework adds users profiles Lambda Function ARN"
Value: !GetAtt PutProfileFunction.Arn
尝试使用 SAM 框架将 lambda 函数和 api 网关部署到云形成 首先我运行命令“sam package”,项目成功部署到我的 s3 存储桶。但是在运行“sam deploy”之后它失败了。它失败并出现错误存储桶位于此区域:us-east-2。请将此区域用于 us-east-2
发出命令 sam deploy --template-file deploy.yaml --stack-name myStack4 后查看以下错误的完整堆栈跟踪
Deploying with following values
===============================
Stack name : mikeStack4
Region : None
Confirm changeset : False
Deployment s3 bucket : None
Capabilities : null
Parameter overrides : {}
Signing Profiles : {}
Initiating deployment
=====================
Waiting for changeset to be created..
CloudFormation stack changeset
-------------------------------------------------------------------------------------------------------------------------
Operation LogicalResourceId ResourceType Replacement
-------------------------------------------------------------------------------------------------------------------------
+ Add PutProfileFunctionPutProfile AWS::Lambda::Permission N/A
PermissionProd
+ Add PutProfileFunction AWS::Lambda::Function N/A
+ Add ServerlessRestApiDeployment7 AWS::ApiGateway::Deployment N/A
5e148f6d0
+ Add ServerlessRestApiProdStage AWS::ApiGateway::Stage N/A
+ Add ServerlessRestApi AWS::ApiGateway::RestApi N/A
-------------------------------------------------------------------------------------------------------------------------
Changeset created successfully. arn:aws:cloudformation:us-west-2:630589988206:changeSet/samcli-deploy1630606751/c1aa856f-4259-4a2d-a4cc-c6a738fb1865
2021-09-02 19:19:19 - Waiting for stack create/update to complete
CloudFormation events from changeset
-------------------------------------------------------------------------------------------------------------------------
ResourceStatus ResourceType LogicalResourceId ResourceStatusReason
-------------------------------------------------------------------------------------------------------------------------
CREATE_IN_PROGRESS AWS::Lambda::Function PutProfileFunction -
CREATE_IN_PROGRESS AWS::Lambda::Function PutProfileFunction Resource creation Initiated
ROLLBACK_IN_PROGRESS AWS::CloudFormation::Stack mikeStack4 The following resource(s)
failed to create:
[PutProfileFunction].
Rollback requested by user.
CREATE_FAILED AWS::Lambda::Function PutProfileFunction Resource handler returned
message: "Error occurred
while GetObject. S3 Error
Code: PermanentRedirect. S3
Error Message: The bucket is
in this region: us-east-2.
Please use this region to
retry the request (Service:
Lambda, Status Code: 400,
Request ID: 9edeeae4-ecd4-4d
58-baec-7bef421657e3,
Extended Request ID: null)"
(RequestToken: 1238ab0d-1fc9
-4f8f-9965-4f41d71e5804,
HandlerErrorCode:
InvalidRequest)
DELETE_IN_PROGRESS AWS::Lambda::Function PutProfileFunction -
ROLLBACK_COMPLETE AWS::CloudFormation::Stack mikeStack4 -
DELETE_COMPLETE AWS::Lambda::Function PutProfileFunction -
-------------------------------------------------------------------------------------------------------------------------
Error: Failed to create/update the stack: mikeStack4, Waiter StackCreateComplete failed: Waiter encountered a terminal failure state: For expression "Stacks[].StackStatus" we matched expected path: "ROLLBACK_COMPLETE" at least once
解决方案
问题出在我的 AWS CLI 配置中的区域
我运行命令 AWS configure 并将区域重置为建议的区域
并且部署成功
推荐阅读
- java - 从 Elasticsearch 索引中检索最小时间戳的最快方法是什么?
- go - 为什么通过 Context 共享状态仅适用于我的请求中间件?
- r - 提高传单的性能
- c++ - Visual Studio Release Build 生成需要 Microsoft.VC80.DebugCRT 的可执行文件
- linux - tar 退出代码 123 是否总是意味着空存档?
- android-studio - android studio 3.1 仅在对话框中找不到设备
- python - Split() 发出期货警告
- javascript - jQuery将字符串变成跨越多个实例
- r - 将图像背景添加到 ggplot barplot 以便图像仅在条形图内可见
- maps - 使用搜索功能将谷歌地图添加到后台设置