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
Resources: | |
# ... | |
HelloWorldFunction: | |
Type: AWS::Serverless::Function | |
Properties: | |
# ... | |
Events: | |
FindApi: | |
Type: Api | |
Properties: |
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
Resources: | |
Api: | |
Type: AWS::Serverless::Api | |
Properties: | |
StageName: !Ref ApiStageName # use our parameter |
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
Parameters: | |
DeploymentStage: | |
Type: String | |
Default: staging | |
AllowedValues: | |
- staging | |
- production | |
Description: Staging or Production deployment. Default is staging. | |
# New parameter for the API Gateway stage name |
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
Mappings: | |
EnvironmentVariables: | |
# mapping keys are the allowed values for DeploymentStage | |
staging: | |
# mapping value is multi-value where key is the environment variable | |
PROD: false | |
API_URL: {staging api endpoint url} | |
production: | |
PROD: true | |
API_URL: {production api endpoint url} |
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
Resources: | |
HelloWorldFunction: | |
Type: AWS::Serverless::Function | |
Properties: | |
CodeUri: hello_world/ | |
Handler: app.lambda_handler | |
Runtime: python3.8 | |
Environment: | |
Variables: | |
# add a variable with the value of the DeploymentStage template parameter |
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
Parameters: | |
DeploymentStage: | |
Type: String | |
Default: staging | |
AllowedValues: | |
- staging | |
- production | |
Description: Staging or production deployment. Default is staging. |
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
Resources: | |
HelloWorldFunction: | |
Type: AWS::Serverless::Function | |
Properties: | |
CodeUri: hello_world/ | |
Handler: app.lambda_handler | |
Runtime: python3.8 | |
Environment: | |
Variables: | |
TABLE_NAME: !Ref MyTable |
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
import os | |
import json | |
import boto3 | |
def lambda_handler(event, context): | |
# environment variables are native, so use a language-specific | |
# method to access them, not the lambda context | |
table = os.environ['TABLE_NAME'] | |
# use the AWS SDK to scan the table by name |
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
Resources: | |
HelloWorldFunction: | |
Type: AWS::Serverless::Function | |
Properties: | |
CodeUri: hello_world/ | |
Handler: app.lambda_handler | |
Runtime: python3.8 | |
# add an environment variable so the code can get the table name | |
Environment: | |
Variables: |
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
Resources: | |
# the hello-world function from the sample project | |
HelloWorldFunction: | |
Type: AWS::Serverless::Function | |
Properties: | |
CodeUri: hello_world/ | |
Handler: app.lambda_handler | |
Runtime: python3.8 | |
Events: | |
HelloWorld: |