Skip to content

Commit

Permalink
Fix ApiGateway.py sample (#666)
Browse files Browse the repository at this point in the history
Correct the ApiGateway sample code so the stack is being created correctly now (original one raises errors during creation).
  • Loading branch information
Paweł Smoliński authored and markpeek committed Feb 21, 2017
1 parent b3cfcba commit 2439839
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
15 changes: 11 additions & 4 deletions examples/ApiGateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from troposphere.apigateway import RestApi, Method
from troposphere.apigateway import Resource, MethodResponse
from troposphere.apigateway import Integration, IntegrationResponse
from troposphere.apigateway import Deployment
from troposphere.apigateway import Deployment, Stage
from troposphere.apigateway import ApiKey, StageKey
from troposphere.iam import Role, Policy
from troposphere.awslambda import Function, Code
Expand Down Expand Up @@ -66,7 +66,7 @@
),
Handler="index.handler",
Role=GetAtt("LambdaExecutionRole", "Arn"),
Runtime="nodejs",
Runtime="nodejs4.3",
))

# Create a resource to map the lambda function to
Expand Down Expand Up @@ -110,18 +110,25 @@

# Create a deployment
stage_name = 'v1'

deployment = t.add_resource(Deployment(
"%sDeployment" % stage_name,
DependsOn="LambdaMethod",
RestApiId=Ref(rest_api),
StageName=stage_name
))

stage = t.add_resource(Stage(
'%sStage' % stage_name,
StageName=stage_name,
RestApiId=Ref(rest_api),
DeploymentId=Ref(deployment)
))

key = t.add_resource(ApiKey(
"ApiKey",
StageKeys=[StageKey(
RestApiId=Ref(rest_api),
StageName=stage_name
StageName=Ref(stage)
)]
))

Expand Down
19 changes: 16 additions & 3 deletions tests/examples_output/ApiGateway.template
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
"RestApiId": {
"Ref": "ExampleApi"
},
"StageName": "v1"
"StageName": {
"Ref": "v1Stage"
}
}
]
},
Expand Down Expand Up @@ -66,7 +68,7 @@
"Arn"
]
},
"Runtime": "nodejs"
"Runtime": "nodejs4.3"
},
"Type": "AWS::Lambda::Function"
},
Expand Down Expand Up @@ -184,12 +186,23 @@
"v1Deployment": {
"DependsOn": "LambdaMethod",
"Properties": {
"RestApiId": {
"Ref": "ExampleApi"
}
},
"Type": "AWS::ApiGateway::Deployment"
},
"v1Stage": {
"Properties": {
"DeploymentId": {
"Ref": "v1Deployment"
},
"RestApiId": {
"Ref": "ExampleApi"
},
"StageName": "v1"
},
"Type": "AWS::ApiGateway::Deployment"
"Type": "AWS::ApiGateway::Stage"
}
}
}

0 comments on commit 2439839

Please sign in to comment.