我喜欢在部署模板时如何创建角色+内联策略:
资源:
MyFUnction:
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:
Description: Enter description of what this specific Lambda does
CodeUri: hello_world/build/
Handler: app.lambda_handler
Runtime: python2.7
Environment: # More info about Env Vars: https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#environment-object
Variables:
PARAM1: VALUE
Policies:
# Using AWSLambdaExecute automatically creates a role named: <StackName>Role-<UUID>
- AWSLambdaExecute
# This policy is assigned as an Inline policy to the role
- Version: '2012-10-17' # Policy Document
Statement:
Effect: Allow
Action: ......现在,我可以参考动态创建的角色并在SAM模板中添加一个输出吗?
发布于 2018-09-19 23:20:09
SAM为您创建的结果角色只是将“角色”添加到末尾的函数的名称。您可以使用这些信息来使用普通的CloudFormation函数获取它的角色或属性。
例如,如果您想访问MyFunction的角色ARN,可以在SAM模板中使用!GetAtt MyFunctionRole.Arn。同样的原则也适用于!Ref和其他功能。
发布于 2019-05-25 04:37:20
我能够测试这方面的解决方案,在SAM template.yaml中,您可以为逻辑ID添加一个输出,就像在CloudFormation中一样,在使用Policies for AWS::Serverless::Function之类的属性时,逻辑ID是为您自动创建的转换的一部分。
得到的IAM角色的逻辑ID是<Function Logical ID>Role,我使用了以下内容:
Outputs:
LambdaRole:
Value:
Fn::GetAtt:
- "LambdaFunctionRole"
- "Arn"
Description: "Lambda IAM Role"https://stackoverflow.com/questions/52413596
复制相似问题