Create a SAM application with the following options:
➜ tutorials > ✗ sam initWhich template source would you like to use?1 - AWS Quick Start Templates2 - Custom Template LocationChoice: 1Choose an AWS Quick Start application template1 - Hello World Example2 - Data processing3 - Hello World Example with Powertools for AWS Lambda4 - Multi-step workflow5 - Scheduled task6 - Standalone function7 - Serverless API8 - Infrastructure event management9 - Lambda Response Streaming10 - Serverless Connector Hello World Example11 - Multi-step workflow with Connectors12 - GraphQLApi Hello World Example13 - Full Stack14 - Lambda EFS example15 - DynamoDB Example16 - Machine LearningTemplate: 1Use the most popular runtime and package type? (Python and zip)[y/N]: yWould you like to enable X-Ray tracing on the function(s)in your application? [y/N]: NWould you like to enable monitoring using CloudWatch Application Insights?For more info, please view https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/cloudwatch-application-insights.html [y/N]: NWould you like to set Structured Logging in JSON format on your Lambda functions? [y/N]: N
Update /template.yaml to pass Upstash Redis environment variables:
/template.yaml
AWSTemplateFormatVersion:'2010-09-09'Transform: AWS::Serverless-2016-10-31Description:> sam-app Sample SAM Template for sam-appGlobals: Function:Timeout:3MemorySize:128Parameters: UpstashRedisRestURL:Type: String UpstashRedisRestToken:Type: StringResources: HelloWorldFunction:Type: AWS::Serverless::Function Properties:CodeUri: hello_world/Handler: app.lambda_handlerRuntime: python3.9 Architectures:- x86_64 Events: HelloWorld:Type: Api Properties:Path: /helloMethod: get Environment: Variables:UPSTASH_REDIS_REST_URL:!Ref UpstashRedisRestURLUPSTASH_REDIS_REST_TOKEN:!Ref UpstashRedisRestTokenOutputs: HelloWorldApi:Description:"API Gateway endpoint URL for Prod stage for Hello World function"Value:!Sub"https://${ServerlessRestApi}.execute-api.${AWS::Region}.amazonaws.com/Prod/hello/" HelloWorldFunction:Description:"Hello World Lambda Function ARN"Value:!GetAtt HelloWorldFunction.Arn HelloWorldFunctionIamRole:Description:"Implicit IAM Role created for Hello World function"Value:!GetAtt HelloWorldFunctionRole.Arn