我正在使用 AWS CLI 部署 SAM 模板。
AWS Api 名称设置为与 CloudFormation 堆栈名称相同。根据下面的模板内容,我希望 Api 被称为“用户”。
是否可以设置 API 名称?
SAM 模板:
MyApi:
Type: AWS::Serverless::Api
Properties:
Name: Users
StageName: default
更新附加信息(用于部署的完整模板和 AWS CLI 命令):
模板:
AWSTemplateFormatVersion: 2010-09-09
Transform: AWS::Serverless-2016-10-31
Resources:
HelloFunction:
Type: AWS::Serverless::Function
Properties:
Handler: main
Runtime: go1.x
Events:
GetEvent:
Type: Api
Properties:
Path: /
Method: post
#RestApiId: !Ref ApiGateway1
LambdaInvokePermission:
Type: AWS::Lambda::Permission
Properties:
FunctionName: !GetAtt
- HelloFunction
- Arn
Action: 'lambda:InvokeFunction'
Principal: apigateway.amazonaws.com
SourceAccount: !Ref 'AWS::AccountId'
MyApi:
Type: AWS::Serverless::Api
Properties:
Name: Users
StageName: default
EndpointConfiguration: REGIONAL
DefinitionBody:
swagger: "2.0"
info:
title: "TestAPI"
paths:
/:
post:
x-amazon-apigateway-integration:
uri:
Fn::Sub: arn:aws:apigateway:${AWS::Region}:lambda:path/2015-03-31/functions/${HelloFunction.Arn}/invocations
responses: {}
httpMethod: "POST"
type: "aws_proxy"
Outputs:
FunctioArn:
Value: !GetAtt HelloFunction.Arn
Export:
Name: HelloFunctionArn
CLI 命令:
aws cloudformation package --template-file template.yml
--output-template-file samtemplate.yaml --s3-bucket (bucketname)
aws cloudformation deploy --template-file samtemplate.yaml
--stack-name apisample-stack --capabilities CAPABILITY_IAM