AWS Sam:无法创建/更新堆栈错误



我正在尝试用AWS Sam构建一个支持S3的测试应用程序。以下是内容。

template.yaml

AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: >
patientcheckout
Sample SAM Template for patientcheckout
# More info about Globals: https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst
Globals:
Function:
Timeout: 20
Runtime: java11
MemorySize: 512
Resources:
PatientCheckoutBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: "!Sub ${AWS::StackName}-${AWS::AccountId}-${AWS::Region}"
PatientCheckoutFunction:
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:
CodeUri: patientcheckout
Handler: com.yohan.lambda.PatientCheckoutLambda::handler
Policies:
- S3ReadPolicy:
BucketName: !Sub ${AWS::StackName}-${AWS::AccountId}-${AWS::Region}
Events:
S3Event:
Type: S3 # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Bucket: !Ref PatientCheckoutBucket
Events: s3:ObjectCreated:*

使用sam build可以成功构建应用程序。在尝试部署时,我们最终会出现此错误。

D:popawslambdapatientcheckout>sam deploy --guided
Configuring SAM deploy
======================
Looking for config file [samconfig.toml] :  Found
Reading default arguments  :  Success
Setting default arguments for 'sam deploy'
=========================================
Stack Name [patientcheckout]: patientcheckout
AWS Region [us-east-1]:
#Shows you resources changes to be deployed and require a 'Y' to initiate deploy
Confirm changes before deploy [y/N]:
#SAM needs permission to be able to create roles to connect to the resources in your template
Allow SAM CLI IAM role creation [Y/n]:
Save arguments to configuration file [Y/n]:
SAM configuration file [samconfig.toml]:
SAM configuration environment [default]:
Looking for resources needed for deployment: Found!
Managed S3 bucket: aws-sam-cli-managed-default-samclisourcebucket-1hmnzbuee9816
A different default S3 bucket can be set in samconfig.toml
Saved arguments to config file
Running 'sam deploy' for future deployments will use the parameters saved above.
The above parameters can be changed by modifying samconfig.toml
Learn more about samconfig.toml syntax at
https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-config.html

Deploying with following values
===============================
Stack name                   : patientcheckout
Region                       : us-east-1
Confirm changeset            : False
Deployment s3 bucket         : aws-sam-cli-managed-default-samclisourcebucket-1hmnzbuee9816
Capabilities                 : ["CAPABILITY_IAM"]
Parameter overrides          : {}
Signing Profiles             : {}
Initiating deployment
=====================
Waiting for changeset to be created..
CloudFormation stack changeset
---------------------------------------------------------------------------------------------------------------------
Operation                     LogicalResourceId             ResourceType                  Replacement
---------------------------------------------------------------------------------------------------------------------
+ Add                         PatientCheckoutBucket         AWS::S3::Bucket               N/A
+ Add                         PatientCheckoutFunctionRole   AWS::IAM::Role                N/A
+ Add                         PatientCheckoutFunctionS3Ev   AWS::Lambda::Permission       N/A
entPermission
+ Add                         PatientCheckoutFunction       AWS::Lambda::Function         N/A
---------------------------------------------------------------------------------------------------------------------
Changeset created successfully. arn:aws:cloudformation:us-east-1:716460586643:changeSet/samcli-deploy1624953681/834f8797-6047-4d72-b368-9d54ea9783ac

2021-06-29 13:31:31 - Waiting for stack create/update to complete
CloudFormation events from changeset
---------------------------------------------------------------------------------------------------------------------
ResourceStatus                ResourceType                  LogicalResourceId             ResourceStatusReason
---------------------------------------------------------------------------------------------------------------------
CREATE_IN_PROGRESS            AWS::IAM::Role                PatientCheckoutFunctionRole   Resource creation Initiated
CREATE_IN_PROGRESS            AWS::IAM::Role                PatientCheckoutFunctionRole   -
CREATE_COMPLETE               AWS::IAM::Role                PatientCheckoutFunctionRole   -
CREATE_IN_PROGRESS            AWS::Lambda::Function         PatientCheckoutFunction       -
CREATE_COMPLETE               AWS::Lambda::Function         PatientCheckoutFunction       -
CREATE_IN_PROGRESS            AWS::Lambda::Function         PatientCheckoutFunction       Resource creation Initiated
CREATE_IN_PROGRESS            AWS::Lambda::Permission       PatientCheckoutFunctionS3Ev   -
entPermission
CREATE_IN_PROGRESS            AWS::Lambda::Permission       PatientCheckoutFunctionS3Ev   Resource creation Initiated
entPermission
CREATE_COMPLETE               AWS::Lambda::Permission       PatientCheckoutFunctionS3Ev   -
entPermission
ROLLBACK_IN_PROGRESS          AWS::CloudFormation::Stack    patientcheckout               The following resource(s)
                    failed to create:
                    [PatientCheckoutBucket].
                    Rollback requested by user.
CREATE_FAILED                 AWS::S3::Bucket               PatientCheckoutBucket         Bad Request (Service:
                    Amazon S3; Status Code:
                    400; Error Code: 400 Bad
                    Request; Request ID:
                    7NRVBFEJSMBTGM0G; S3
                    Extended Request ID: 9tGgby
                    nxYIq05EvkwIF8KZgbQNoGEOfkI
                    Hsl+DoKYcGSyh1Ti4Et/pVZG/uS
                    0LfgFR+WYyZV++k=; Proxy:
                    null)
CREATE_IN_PROGRESS            AWS::S3::Bucket               PatientCheckoutBucket         -
DELETE_COMPLETE               AWS::S3::Bucket               PatientCheckoutBucket         -
DELETE_IN_PROGRESS            AWS::Lambda::Permission       PatientCheckoutFunctionS3Ev   -
entPermission
DELETE_IN_PROGRESS            AWS::Lambda::Function         PatientCheckoutFunction       -
DELETE_COMPLETE               AWS::Lambda::Permission       PatientCheckoutFunctionS3Ev   -
entPermission
DELETE_COMPLETE               AWS::Lambda::Function         PatientCheckoutFunction       -
DELETE_IN_PROGRESS            AWS::IAM::Role                PatientCheckoutFunctionRole   -
ROLLBACK_COMPLETE             AWS::CloudFormation::Stack    patientcheckout               -
DELETE_COMPLETE               AWS::IAM::Role                PatientCheckoutFunctionRole   -
---------------------------------------------------------------------------------------------------------------------
Error: Failed to create/update the stack: patientcheckout, Waiter StackCreateComplete failed: Waiter encountered a terminal failure state: For expression "Stacks[].StackStatus" we matched expected path: "ROLLBACK_COMPLETE" at least once

我该怎么解决这个问题?

The following resource(s) failed to create: [PatientCheckoutBucket].

要修复此问题,请提供一个更简单的bucket名称。遵循此处列出的命名规则:https://docs.aws.amazon.com/AmazonS3/latest/userguide/bucketnamingrules.html

下面是一个使用模板参数的示例,因此您为sam deploy --guided输入的任何内容都将保存到.toml文件中。当我们在那里的时候,让我们使用S3ReadPolicy:的Bucket Ref

Parameters:
MyBucketName:
Type: String
Default: "default-bucketname"
Resources:
PatientCheckoutBucket:
Type: AWS::S3::Bucket
Properties:
BucketName: !Sub "prefix-${MyBucketName}-suffix"
PatientCheckoutFunction:
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:
CodeUri: patientcheckout
Handler: com.yohan.lambda.PatientCheckoutLambda::handler
Policies:
- S3ReadPolicy:
BucketName: !Ref PatientCheckoutBucket
Events:
S3Event:
Type: S3 # More info about API Event Source: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#api
Properties:
Bucket: !Ref PatientCheckoutBucket
Events: s3:ObjectCreated:*

相关内容

  • 没有找到相关文章

最新更新