Last active
November 10, 2021 00:06
-
-
Save gmariette/8d8e0b414ef4c74eb38c92844a6fa426 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| AWSTemplateFormatVersion: 2010-09-09 | |
| Description: Medium custom lambda stack | |
| Resources: | |
| CustomBackedLambda: | |
| Type: AWS::Lambda::Function | |
| Properties: | |
| FunctionName: CustomBackedLambda | |
| Runtime: python3.9 | |
| Role: my_iam_role | |
| Handler: index.lambda_handler | |
| Timeout: 90 | |
| Code: | |
| ZipFile: | | |
| import cfnresponse | |
| import logging | |
| import random | |
| # Init of the logging module | |
| logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s') | |
| def lambda_handler(event, context): | |
| if event.get('RequestType') == 'Create': | |
| number = random.randint(0,1000) | |
| message = f"This code is finally working after {number} times!" if number > 500 else f"This crappy code is still not working after {number} times!" | |
| responseData = {} | |
| responseData['message'] = message | |
| logging.info('Sending %s to cloudformation', responseData['message']) | |
| cfnresponse.send(event, context, cfnresponse.SUCCESS, responseData) | |
| elif event.get('RequestType') == 'Delete': | |
| responseData = {} | |
| responseData['message'] = "Goodbye from lambda" | |
| logging.info('Sending %s to cloudformation', responseData['message']) | |
| cfnresponse.send(event, context, cfnresponse.SUCCESS, responseData) | |
| else: | |
| logging.error('Unknown operation: %s', event.get('RequestType')) | |
| Environment: | |
| Variables: | |
| myvar: var01 | |
| Description: Custom lambda cloudformation | |
| InvokeCustomLambda: | |
| DependsOn: CustomBackedLambda | |
| Type: Custom::InvokeCustomLambda | |
| Properties: | |
| ServiceToken: !GetAtt CustomBackedLambda.Arn | |
| Outputs: | |
| CustomLambdaOutput: | |
| Description: Message from custom lambda | |
| Value: !GetAtt InvokeCustomLambda.message |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment