Skip to content

Instantly share code, notes, and snippets.

@erbrito
Created October 21, 2016 14:48
Show Gist options
  • Save erbrito/4d3a643529f89d31c53ce82da05a7799 to your computer and use it in GitHub Desktop.
Save erbrito/4d3a643529f89d31c53ce82da05a7799 to your computer and use it in GitHub Desktop.
Stack to create all that is needed for Project with DyanamoDb, ApiGateway and an Event Rule trigger (Crhon to launch a lambda function) stack. The lambda is created with the import export tool using a swager definition. Requires AWS-CLI and credentials to be configured.
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "Stack to create all that is needed for Project with DyanamoDb, ApiGateway and an Event Rule trigger (Crhon to launch a lambda function) stack. The lambda is created with the import export tool using a swager definition",
"Parameters": {
"DynamoDbTableName": {
"Default": "@DynamoDbTableName@",
"Type": "String"
},
"DynamoDbIdName":{
"Default": "id",
"Type": "String"
},
"RestApiName": {
"Default": "@aws_rest_api_name@",
"Type": "String"
},
"CronRateExpression": {
"Default": "rate(@timeRateToTriggerJobInMinutes@ minutes)",
"Type": "String"
},
"DurationBeforeExpireServiceInMinutes": {
"Default": @durationBeforeExpireServiceInMinutes@,
"Type": "Number"
}
},
"Resources": {
"myDynamoDBTable": {
"Type": "AWS::DynamoDB::Table",
"Properties": {
"AttributeDefinitions":
[
{
"AttributeName": "id",
"AttributeType": "S"
}
],
"KeySchema":
[
{
"AttributeName": "id",
"KeyType": "HASH"
}
],
"ProvisionedThroughput": {
"ReadCapacityUnits": "1",
"WriteCapacityUnits": "1"
},
"TableName": {"Ref": "DynamoDbTableName"}
}
},
"MyRestApi": {
"Type": "AWS::ApiGateway::RestApi",
"Properties": {
"Description": "** This is the second draft of the PDM Api that includes 3 services: post service , get service & post device results **",
"Name": {"Ref": "RestApiName"}
}
},
"CronTrigger": {
"Type": "AWS::Events::Rule",
"Properties": {
"Description": "Cron job to trigger lambda to send incomplete results for expired services",
"Name": "cronUpdateServices-@lambdaFunction@",
"ScheduleExpression": {"Ref": "CronRateExpression"},
"State": "ENABLED",
"Targets": [
{
"Arn": "arn:aws:lambda:us-east-1:@awsAccount@:function:@lambdaFunction@",
"Id": "Id2980019567731",
"Input": {"Fn::Join": [" ", ["{\"action\": \"expireBundles\", \n \"duration\": ", {"Ref": "DurationBeforeExpireServiceInMinutes"}, ", \n \"tableName\": \"@DynamoDbTableName@\", \n \"clientId\": \"@clientId@\", \n \"recordingBasicEncodedCred\": \"@recordingBasicEncodedCred@\", \n\"recordingContextRecording\": \"@recordingContextRecording@\",\n \"recordingHostAddress\": \"@recordingHostAddress@\", \n \"recordingRootPath\": \"@recordingRootPath@\", \n \"recordingVersionRecordingPath\": \"@recordingVersionRecordingPath@\", \n \"recordingTimeOutMilliSec\": \"@recordingTimeOutMilliSec@\" \n}"]]}
}]
}
}
},
"Outputs": {
"RestApiId": {
"Value": {"Ref": "MyRestApi"},
"Description": "the rest api id"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment