Created
February 21, 2021 11:28
-
-
Save abranhe/a8708c9787df27415b27d13213394ea3 to your computer and use it in GitHub Desktop.
Cloudformation Lamda Random Value
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Just adding support for a lambda | |
LambdaExecutionRole: | |
Type: AWS::IAM::Role | |
Properties: | |
AssumeRolePolicyDocument: | |
Version: '2012-10-17' | |
Statement: | |
- Effect: Allow | |
Principal: | |
Service: | |
- lambda.amazonaws.com | |
Action: | |
- sts:AssumeRole | |
Policies: | |
- PolicyName: allowLambdaLogging | |
PolicyDocument: | |
Version: '2012-10-17' | |
Statement: | |
- Effect: 'Allow' | |
Action: | |
- 'logs:*' | |
Resource: '*' | |
# Generate a random color for the text in the webserver | |
# Taken from https://www.itonaut.com/2018/01/03/generate-passwords-in-aws-cloudformation-template/ | |
LambdaFunction: | |
Type: AWS::Lambda::Function | |
Properties: | |
Code: | |
ZipFile: > | |
const response = require('cfn-response'); | |
exports.handler = (event, context) => { | |
// https://stackoverflow.com/a/5365036/7602110 | |
const responseData = {RandomColor: `#${((1<<24) * Math.random() | 0).toString(16)}`}; | |
response.send(event, context, response.SUCCESS, responseData); | |
}; | |
Handler: index.handler | |
Runtime: nodejs12.x | |
Role: !GetAtt LambdaExecutionRole.Arn | |
MemorySize: 128 | |
Timeout: 20 | |
# Custom Resource | |
ColorString: | |
Type: AWS::CloudFormation::CustomResource | |
Properties: | |
Length: 7 | |
ServiceToken: !GetAtt LambdaFunction.Arn |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage: