Skip to content

Instantly share code, notes, and snippets.

@quinceleaf
Created October 5, 2020 05:53
Show Gist options
  • Save quinceleaf/0989e05b3564801dfe737dd7a3581ede to your computer and use it in GitHub Desktop.
Save quinceleaf/0989e05b3564801dfe737dd7a3581ede to your computer and use it in GitHub Desktop.
Example: creating AWS SSM Parameter via SAM template
Example to demonstrate creating parameters in AWS SSM Parameter Store that reference resources created via the Serverless Application Model
==================================================
LAMBDA FUNCTION hello_world.py:
import json
def lambda_handler(event, context):
response = {
"isBase64Encoded": "false",
"headers": {
"Access-Control-Allow-Headers": "Content-Type",
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "OPTIONS,POST,GET",
},
}
response["statusCode"] = 200
response["body"] = json.dumps("Hello World")
return response
==================================================
AWSTemplateFormatVersion: "2010-09-09"
Transform: "AWS::Serverless-2016-10-31"
Description: "Test SSM Creation"
Globals:
Function:
Timeout: 30
Resources:
# ––– APPLICATION / LAMBDAS
HelloWorldFunction:
Type: AWS::Serverless::Function
Properties:
Handler: hello_world.lambda_handler
Runtime: python3.8
MemorySize: 128
Timeout: 6
Tracing: Active
FunctionName: !Sub ${AWS::StackName}-HelloWorld
Description: !Sub
- Function ${ResourceName}
- ResourceName: HelloWorld
CodeUri: functions/test/hello_world.py
Policies:
- AWSXrayWriteOnlyAccess
# ––– APPLICATION / SSM
HelloWorldParameter:
DependsOn:
- HelloWorldFunction
Type: AWS::SSM::Parameter
Properties:
DataType: text
Description: "References ARN of Lambda"
Name: "HelloWorldLambdaARN"
Tier: Standard
Type: String
Value: !GetAtt HelloWorldFunction.Arn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment