Outputs:
HelloWorldApi:
Description: "API Gateway endpoint URL for Prod environment"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
sam deploy --template-file .aws-sam/build/template.yaml --stack-name HelloWorld --region us-east-1 --capabilities CAPABILITY_IAM
最终的“template.yaml”文件:
Transform: 'AWS::Serverless-2016-10-31'
Resources:
HelloWorldFunction:
Type: 'AWS::Serverless::Function'
Properties:
Handler: app.lambda_handler
Runtime: python3.6
CodeUri: .
HelloWorldApi:
Type: 'AWS::Serverless::Api'
Properties:
StageName: Prod
HelloWorldApiDeployment:
Type: 'AWS::Serverless::Deployment'
Properties:
Description: "Deployment package for the HelloWorld API"
HelloWorldPermission:
Type: 'AWS::Lambda::Permission'
Properties:
FunctionName: !GetAtt HelloWorldFunction.Arn
Action: 'lambda:InvokeFunction'
Principal: apigateway.amazonaws.com
HelloWorldMethod:
Type: 'AWS::ApiGateway::Method'
Properties:
AuthorizationType: NONE
HttpMethod: GET
Integration:
Type: AWS_PROXY
IntegrationHttpMethod: POST
Uri: !Sub "arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HelloWorldFunction.Arn}/invocations"
ResourceId: !GetAtt HelloWorldApi.RootResourceId
RestApiId: !Ref HelloWorldApi
Outputs:
HelloWorldApi:
Description: "API Gateway endpoint URL for Prod environment"
Value: !Sub "https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/"
上一篇:部署AWSLambda使用Serverless时,出现'Therequestsignaturewecalculateddoesnotmatchthesignatureyouprovided.”错误。