### Example OIDC Setup for AWS SAM Pipeline Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/deploying-with-oidc.md This example demonstrates the interactive prompts and user inputs required during the `sam pipeline bootstrap` process to configure OIDC authentication with GitHub Actions. It covers selecting OIDC, specifying provider details, and confirming resource creation. ```bash Select a permissions provider: 1 - IAM (default) 2 - OpenID Connect (OIDC) Choice (1, 2): 2 Select an OIDC provider: 1 - GitHub Actions 2 - GitLab 3 - Bitbucket Choice (1, 2, 3): 1 Enter the URL of the OIDC provider [https://token.actions.githubusercontent.com]: Enter the OIDC client ID (sometimes called audience) [sts.amazonaws.com]: Enter the GitHub organization that the code repository belongs to. If there is no organization enter your username instead: my-org Enter GitHub repository name: testing Enter the name of the branch that deployments will occur from [main]: [3] Reference application build resources Enter the pipeline execution role ARN if you have previously created one, or we will create one for you []: Enter the CloudFormation execution role ARN if you have previously created one, or we will create one for you []: Please enter the artifact bucket ARN for your Lambda function. If you do not have a bucket, we will create one for you []: Does your application contain any IMAGE type Lambda functions? [y/N]: [4] Summary Below is the summary of the answers: 1 - Account: 123456 2 - Stage configuration name: dev 3 - Region: us-east-1 4 - OIDC identity provider URL: https://token.actions.githubusercontent.com 5 - OIDC client ID: sts.amazonaws.com 6 - GitHub organization: my-org 7 - GitHub repository: testing 8 - Deployment branch: main 9 - Pipeline execution role: [to be created] 10 - CloudFormation execution role: [to be created] 11 - Artifacts bucket: [to be created] 12 - ECR image repository: [skipped] Press enter to confirm the values above, or select an item to edit the value: This will create the following required resources for the 'dev' configuration: - IAM OIDC Identity Provider - Pipeline execution role - CloudFormation execution role - Artifact bucket Should we proceed with the creation? [y/N]: ``` -------------------------------- ### Choosing an AWS Quick Start Template Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/using-sam-cli-init.md This interactive prompt guides you through selecting an AWS Quick Start Template for your project. You first choose the template source and then a specific application template. ```bash Which template source would you like to use? 1 - AWS Quick Start Templates 2 - Custom Template Location Choice: {{1}} Choose an AWS Quick Start application template 1 - Hello World Example 2 - Multi-step workflow 3 - Serverless API 4 - Scheduled task 5 - Standalone function 6 - Data processing 7 - Hello World Example With Powertools 8 - Infrastructure event management 9 - Serverless Connector Hello World Example 10 - Multi-step workflow with Connectors 11 - Lambda EFS example 12 - DynamoDB Example 13 - Machine Learning Template: {{4}} ``` -------------------------------- ### Example samconfig.toml File Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-config.md Demonstrates a TOML-formatted `samconfig.toml` file with configurations for default, build, deploy, sync, and local start API parameters, as well as a 'prod' environment. ```toml version = 0.1 [default] [default.global] [default.global.parameters] stack_name = "sam-app" [default.build.parameters] cached = true parallel = true [default.deploy.parameters] capabilities = "CAPABILITY_IAM" confirm_changeset = true resolve_s3 = true [default.sync.parameters] watch = true [default.local_start_api.parameters] warm_containers = "EAGER" [prod] [prod.sync] [prod.sync.parameters] watch = false ``` -------------------------------- ### Example Nightly Build Version Output Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/manage-sam-cli-versions.md This is an example of the output you would see when verifying the nightly build installation. ```text SAM CLI, version {{1.20.0.dev202103151200}} ``` -------------------------------- ### Verify Installer Choices Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.md Use the 'installer' command with the '-showChoicesAfterApplyingChangesXML' flag to preview the installation preferences before applying them. ```bash $ installer -pkg {{path-to-pkg-installer}} \ -target CurrentUserHomeDirectory \ -showChoicesAfterApplyingChangesXML {{path-to-your-xml-file}} ``` -------------------------------- ### Example Guided Deployment Interactive Prompts Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/using-sam-cli-deploy.md This output shows the interactive prompts during a guided deployment. Brackets indicate default values, and pressing Enter accepts the default. Responses are saved to `samconfig.toml`. ```bash sam-app $ sam deploy --guided Configuring SAM deploy ====================== Looking for config file [samconfig.toml] : Found Reading default arguments : Success Setting default arguments for 'sam deploy' ========================================= Stack Name [sam-app]: {{ENTER}} AWS Region [us-west-2]: {{ENTER}} #Shows you resources changes to be deployed and require a 'Y' to initiate deploy Confirm changes before deploy [Y/n]: {{ENTER}} #SAM needs permission to be able to create roles to connect to the resources in your template Allow SAM CLI IAM role creation [Y/n]: {{ENTER}} #Preserves the state of previously provisioned resources when an operation fails Disable rollback [y/N]: {{ENTER}} HelloWorldFunction may not have authorization defined, Is this okay? [y/N]: {{y}} Save arguments to configuration file [Y/n]: {{ENTER}} SAM configuration file [samconfig.toml]: {{ENTER}} SAM configuration environment [default]: {{ENTER}} ``` -------------------------------- ### Interactive SAM Deploy Guided Flow Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-config.md This example shows an interactive session with the `sam deploy --guided` command, illustrating how configuration values are prompted and potentially saved to `samconfig.toml`. ```bash $ sam deploy --guided Configuring SAM deploy ====================== Looking for config file [samconfig.toml] : Found Reading default arguments : Success Setting default arguments for 'sam deploy' ========================================= Stack Name [sam-app]: {{ENTER}} AWS Region [us-west-2]: {{ENTER}} #Shows you resources changes to be deployed and require a 'Y' to initiate deploy Confirm changes before deploy [Y/n]: {{n}} #SAM needs permission to be able to create roles to connect to the resources in your template Allow SAM CLI IAM role creation [Y/n]: {{ENTER}} #Preserves the state of previously provisioned resources when an operation fails Disable rollback [y/N]: {{ENTER}} HelloWorldFunction may not have authorization defined, Is this okay? [y/N]: {{y}} Save arguments to configuration file [Y/n]: {{ENTER}} SAM configuration file [samconfig.toml]: {{ENTER}} SAM configuration environment [default]: {{ENTER}} ``` -------------------------------- ### Example AWS SAM CLI Guided Deploy Interactive Flow Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-getting-started-hello-world.md This is an example of the interactive prompts and user inputs during the `sam deploy --guided` process. It shows how to configure stack name, region, confirmation, IAM role creation, rollback, authorization, and saving configuration. ```bash $ sam deploy --guided Configuring SAM deploy ====================== Looking for config file [samconfig.toml] : Found Reading default arguments : Success Setting default arguments for 'sam deploy' ========================================= Stack Name [sam-app]: ENTER AWS Region [us-west-2]: ENTER #Shows you resources changes to be deployed and require a 'Y' to initiate deploy Confirm changes before deploy [Y/n]: n #SAM needs permission to be able to create roles to connect to the resources in your template Allow SAM CLI IAM role creation [Y/n]: ENTER #Preserves the state of previously provisioned resources when an operation fails Disable rollback [y/N]: ENTER HelloWorldFunction may not have authorization defined, Is this okay? [y/N]: y Save arguments to configuration file [Y/n]: ENTER SAM configuration file [samconfig.toml]: ENTER SAM configuration environment [default]: ENTER ``` -------------------------------- ### Example Api Event Configuration Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-statemachine-statemachineapi.md Illustrates how to configure an Api event source for a State Machine in an AWS SAM template. This example shows the basic setup for a GET request on '/path'. ```yaml Events: ApiEvent: Type: Api Properties: Path: /path Method: get ``` -------------------------------- ### Start a local API server Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-local-start-api.md Starts a local server to test your application via API. Ensure your application is installed and Docker is running. ```bash $ sam local start-api --port 3000 ``` -------------------------------- ### Example SAM Deploy Command and Output Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/using-sam-cli.md Illustrates the format of a guided SAM deployment command and its interactive output. Use this to understand how to provide input for stack name, region, and deployment confirmations. ```bash $ sam deploy --guided --template {{template.yaml}} Configuring SAM deploy ====================== Looking for config file [samconfig.toml] : Found Reading default arguments : Success Setting default arguments for 'sam deploy' ========================================= Stack Name [sam-app]: {{ENTER}} AWS Region [us-west-2]: {{ENTER}} #Shows you resources changes to be deployed and require a 'Y' to initiate deploy Confirm changes before deploy [y/N]: {{ENTER}} #SAM needs permission to be able to create roles to connect to the resources in your template Allow SAM CLI IAM role creation [Y/n]: {{ENTER}} #Preserves the state of previously provisioned resources when an operation fails Disable rollback [y/N]: {{ENTER}} HelloWorldFunction may not have authorization defined, Is this okay? [y/N]: {{y}} Save arguments to configuration file [Y/n]: {{ENTER}} SAM configuration file [samconfig.toml]: {{ENTER}} SAM configuration environment [default]: {{ENTER}} ``` -------------------------------- ### Starting API locally with sam local start-api and Terraform Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/using-samcli-terraform.md Run this command to use `sam local start-api` with Terraform. Docker must be installed and configured. ```bash $ sam local start-api --hook-name terraform ``` -------------------------------- ### Initialize Finch Virtual Machine on macOS Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-finch.md Perform the initial setup for the Finch virtual machine on macOS. This is a one-time setup. ```bash $ finch vm init ``` -------------------------------- ### Switch to Community Homebrew Installer (Individual Steps) Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/manage-sam-cli-versions.md Switch from the AWS managed Homebrew installer to the community managed installer by executing commands individually. ```bash $ brew uninstall aws-sam-cli ``` ```bash $ which sam ``` ```text sam not found ``` ```bash $ brew untap aws/tap ``` ```text Error: Refusing to untap aws/tap because it contains the following installed formulae or casks: aws-sam-cli-nightly ``` ```bash $ brew cleanup aws/tap ``` ```bash $ brew update ``` ```bash $ brew install aws-sam-cli ``` ```bash $ sam --version ``` ```text SAM CLI, version {{1.94.0}} ``` -------------------------------- ### Example Dockerfile for Lambda function Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-using-build.md This Dockerfile specifies the base image, copies application code and dependencies, and installs requirements. It also sets the default command for the Lambda function. ```dockerfile FROM public.ecr.aws/lambda/python:3.12 COPY app.py requirements.txt ./ RUN python3.12 -m pip install -r requirements.txt # Overwrite the command by providing a different command directly in the template. CMD ["app.lambda_handler"] ``` -------------------------------- ### Start a local HTTP server Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/using-sam-cli-local-start-api.md Run this command from your project's root directory to start a local HTTP server for testing Lambda functions. ```bash sam local start-api {{}} ``` -------------------------------- ### Start Docker Service Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-docker.md Starts the Docker service on a Linux instance. ```bash $ sudo service docker start ``` -------------------------------- ### Switch to Community Homebrew Installer (Single Command) Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/manage-sam-cli-versions.md Switch from the AWS managed Homebrew installer to the community managed installer in a single command. ```bash $ brew uninstall aws-sam-cli && brew untap aws/tap && brew cleanup aws/tap && brew update && brew install aws-sam-cli ``` -------------------------------- ### Start Finch Virtual Machine on macOS Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-finch.md Start the Finch virtual machine to enable its services. ```bash $ finch vm start ``` -------------------------------- ### Install Amazon.Lambda.Tools Global Tool Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/build-dotnet7.md Install the Amazon.Lambda.Tools .NET Core Global Tool for .NET Lambda development. ```bash dotnet tool install -g Amazon.Lambda.Tools ``` -------------------------------- ### Function Scaling Configuration Example Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-function-functionscalingconfig.md This example demonstrates how to configure the minimum and maximum number of execution environments for a Lambda function version using FunctionScalingConfig. ```yaml FunctionScalingConfig: MinExecutionEnvironments: 5 MaxExecutionEnvironments: 100 ``` -------------------------------- ### Example Project Directory Structure Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/using-sam-cli-init.md This illustrates the typical file and folder organization created by `sam init` for a serverless application. ```tree sam-app ├── README.md ├── __init__.py ├── events │ └── event.json ├── hello_world │ ├── __init__.py │ ├── app.py │ └── requirements.txt ├── samconfig.toml ├── template.yaml └── tests ├── __init__.py ├── integration │ ├── __init__.py │ └── test_api_gateway.py ├── requirements.txt └── unit ├── __init__.py └── test_handler.py ``` -------------------------------- ### AWS SAM Init Interactive Flow Example Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-getting-started-hello-world.md This example demonstrates the interactive prompts and choices during the `sam init` command for setting up a Hello World application. ```bash $ sam init {{...}} Which template source would you like to use? 1 - AWS Quick Start Templates 2 - Custom Template Location Choice: 1 Choose an AWS Quick Start application template 1 - Hello World Example 2 - Data processing 3 - Hello World Example with Powertools for AWS Lambda 4 - Multi-step workflow 5 - Scheduled task 6 - Standalone function 7 - Serverless API 8 - Infrastructure event management 9 - Lambda Response Streaming 10 - GraphQLApi Hello World Example 11 - Full Stack 12 - Lambda EFS example 13 - Serverless Connector Hello World Example 14 - Multi-step workflow with Connectors 15 - DynamoDB Example 16 - Machine Learning Template: 1 Use the most popular runtime and package type? (Python and zip) [y/N]: y Would you like to enable X-Ray tracing on the function(s) in your application? [y/N]: ENTER Would 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]: ENTER Would you like to set Structured Logging in JSON format on your Lambda functions? [y/N]: ENTER Project name [sam-app]: ENTER ``` -------------------------------- ### Initialize a Go Application with SAM CLI Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/using-sam-cli-build.md Use `sam init` to create a new serverless application. This example initializes a Go project, specifying the Go runtime and zip package type. ```bash $ sam init {{...}} Which template source would you like to use? 1 - AWS Quick Start Templates 2 - Custom Template Location Choice: {{1}} Choose an AWS Quick Start application template 1 - Hello World Example 2 - Multi-step workflow 3 - Serverless API {{...}} Template: {{1}} Use the most popular runtime and package type? (Python and zip) [y/N]: {{ENTER}} Which runtime would you like to use? {{...}} 4 - dotnetcore3.1 5 - go1.x 6 - go (provided.al2) {{...}} Runtime: {{5}} What package type would you like to use? 1 - Zip 2 - Image Package type: {{1}} Based on your selections, the only dependency manager available is mod. We will proceed copying the template using mod. Would you like to enable X-Ray tracing on the function(s) in your application? [y/N]: {{ENTER}} Would 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]: {{ENTER}} Project name [sam-app]: {{ENTER}} Cloning from https://github.com/aws/aws-sam-cli-app-templates (process may take a moment) ----------------------- Generating application: ----------------------- Name: sam-app Runtime: go1.x Architectures: x86_64 Dependency Manager: mod Application Template: hello-world Output Directory: . Configuration file: sam-app/samconfig.toml Next steps can be found in the README file at sam-app-go/README.md {{...}} ``` -------------------------------- ### Example Pip Dependency Conflict Error Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-troubleshooting.md This error occurs when pip's dependency resolver conflicts with installed packages, often due to incompatible versions of aws-sam-cli and aws-sam-translator. It is recommended to use the native package installer or a virtual environment for pip installations. ```text ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts. aws-sam-cli 1.58.0 requires aws-sam-translator==1.51.0, but you have aws-sam-translator 1.58.0 which is incompatible. aws-sam-cli 1.58.0 requires typing-extensions==3.10.0.0, but you have typing-extensions 4.4.0 which is incompatible. ``` -------------------------------- ### Initialize AWS SAM Hello World Application Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-getting-started-hello-world.md Use this command to create a new serverless application project. It prompts for configuration details like template, runtime, and project name. ```bash $ sam init ``` -------------------------------- ### Initialize a Hello World Application with SAM CLI Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/using-sam-cli-deploy.md Use `sam init` to create a new serverless application. This example initializes a Python 3.9 application using container image packaging. ```bash $ sam init ... Which template source would you like to use? 1 - AWS Quick Start Templates 2 - Custom Template Location Choice: {{1}} Choose an AWS Quick Start application template 1 - Hello World Example 2 - Multi-step workflow ... Template: {{1}} Use the most popular runtime and package type? (Python and zip) [y/N]: {{ENTER}} Which runtime would you like to use? 1 - aot.dotnet7 (provided.al2) ... 15 - nodejs12.x 16 - python3.9 17 - python3.8 ... Runtime: {{16}} What package type would you like to use? 1 - Zip 2 - Image Package type: {{2}} Based on your selections, the only dependency manager available is pip. We will proceed copying the template using pip. ... Project name [sam-app]: {{ENTER}} ----------------------- Generating application: ----------------------- Name: sam-app Base Image: amazon/python3.9-base Architectures: x86_64 Dependency Manager: pip Output Directory: . Configuration file: sam-app/samconfig.toml Next steps can be found in the README file at sam-app/README.md ... ``` -------------------------------- ### Initialize Rust SAM Application Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/building-rust.md Use `sam init` to create a new serverless application. Select the 'Hello World Example' template and the 'rust (provided.al2)' runtime. This sets up the project structure and configuration files. ```bash $ sam init ... Which template source would you like to use? 1 - AWS Quick Start Templates 2 - Custom Template Location Choice: {{1}} Choose an AWS Quick Start application template 1 - Hello World Example 2 - Multi-step workflow 3 - Serverless API ... Template: {{1}} Use the most popular runtime and package type? (Python and zip) [y/N]: {{ENTER}} Which runtime would you like to use? 1 - dotnet8 2 - dotnet6 3 - go (provided.al2) ... 18 - python3.11 19 - python3.10 20 - ruby4.0 21 - ruby3.3 22 - ruby3.2 23 - rust (provided.al2) 24 - rust (provided.al2023) Runtime: {{23}} Based on your selections, the only Package type available is Zip. We will proceed to selecting the Package type as Zip. Based on your selections, the only dependency manager available is cargo. We will proceed copying the template using cargo. Would you like to enable X-Ray tracing on the function(s) in your application? [y/N]: {{ENTER}} Would 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]: {{ENTER}} Project name [sam-app]: {{hello-rust}} ----------------------- Generating application: ----------------------- Name: hello-rust Runtime: rust (provided.al2) Architectures: x86_64 Dependency Manager: cargo Application Template: hello-world Output Directory: . Configuration file: hello-rust/samconfig.toml Next steps can be found in the README file at hello-rust/README.md Commands you can use next ========================= [*] Create pipeline: cd hello-rust && sam pipeline init --bootstrap [*] Validate SAM template: cd hello-rust && sam validate [*] Test Function in the Cloud: cd hello-rust && sam sync --stack-name {stack-name} --watch ``` -------------------------------- ### Basic YAML Configuration for AWS SAM CLI Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/using-sam-cli-configure.md Example of a samconfig.yaml file specifying parameters for default, build, deploy, sync, and local start api commands. ```yaml version 0.1 default: global: parameters: stack_name: sam-app build: parameters: cached: true parallel: true deploy: parameters: capabilities: CAPABILITY_IAM confirm_changeset: true resolve_s3: true sync: parameters: watch: true local_start_api: parameters: warm_containers: EAGER prod: sync: parameters: watch: false ``` -------------------------------- ### Initialize Hello World Application with SAM CLI Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/deploy-upload-local-files.md Initializes a new SAM application. Use this to set up a basic project structure for your serverless application. ```bash $ sam init ... Which template source would you like to use? 1 - AWS Quick Start Templates 2 - Custom Template Location Choice: {{1}} Choose an AWS Quick Start application template 1 - Hello World Example 2 - Multi-step workflow ... Template: {{1}} Use the most popular runtime and package type? (Python and zip) [y/N]: {{y}} Would you like to enable X-Ray tracing on the function(s) in your application? [y/N]: {{ENTER}} Would 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]: {{ENTER}} Project name [sam-app]: {{demo}} ----------------------- Generating application: ----------------------- Name: demo Runtime: python3.9 Architectures: x86_64 Dependency Manager: pip Application Template: hello-world Output Directory: . Configuration file: demo/samconfig.toml ... ``` -------------------------------- ### Lambda TOKEN authorizer example (AWS::Serverless::Api) Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-controlling-access-to-apis-lambda-authorizer.md Configure a Lambda TOKEN authorizer for an AWS::Serverless::Api resource. This setup controls API access based on a token provided in the request. ```yaml Resources: MyApi: Type: AWS::Serverless::Api Properties: StageName: Prod Auth: DefaultAuthorizer: MyLambdaTokenAuthorizer Authorizers: MyLambdaTokenAuthorizer: FunctionArn: !GetAtt MyAuthFunction.Arn MyFunction: Type: AWS::Serverless::Function Properties: CodeUri: ./src Handler: index.handler Runtime: nodejs12.x Events: GetRoot: Type: Api Properties: RestApiId: !Ref MyApi Path: / Method: get MyAuthFunction: Type: AWS::Serverless::Function Properties: CodeUri: ./src Handler: authorizer.handler Runtime: nodejs12.x ``` -------------------------------- ### Define a Simple API with a Lambda Function Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-resource-api.md This example shows a basic AWS SAM template defining a Serverless::Api resource and a Serverless::Function that is triggered by a GET request to the root path. It uses the Ref intrinsic function to link the API event to the ApiGatewayApi resource. ```yaml AWSTemplateFormatVersion: '2010-09-09' Transform: AWS::Serverless-2016-10-31 Description: AWS SAM template with a simple API definition Resources: ApiGatewayApi: Type: AWS::Serverless::Api Properties: StageName: prod ApiFunction: # Adds a GET method at the root resource via an Api event Type: AWS::Serverless::Function Properties: Events: ApiEvent: Type: Api Properties: Path: / Method: get RestApiId: Ref: ApiGatewayApi Runtime: python3.10 Handler: index.handler InlineCode: | def handler(event, context): return {'body': 'Hello World!', 'statusCode': 200} ``` -------------------------------- ### Homebrew Installer Warning for AWS SAM CLI Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-troubleshooting.md This warning appears when installing the AWS SAM CLI via Homebrew, indicating that AWS will no longer maintain this installer. Use AWS-supported installation methods or the community-managed installer. ```text Warning: ... AWS will no longer maintain the Homebrew installer for AWS SAM (aws/tap/aws-sam-cli). For AWS supported installations, use the first party installers ... ``` -------------------------------- ### Go Application Directory Structure Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/using-sam-cli-build.md This is an example of the directory structure created by `sam init` for a Go application. It includes the main application code, configuration files, and event templates. ```tree sam-app ├── Makefile ├── README.md ├── events │ └── event.json ├── hello-world │ ├── go.mod │ ├── go.sum │ ├── main.go │ └── main_test.go ├── samconfig.toml └── template.yaml ``` -------------------------------- ### Check Terraform installation Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/gs-terraform-support.md Run this command to verify if Terraform is installed. If it is, the command will output the installed version. ```bash $ terraform -version ``` -------------------------------- ### Get help for sam build Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-using-build.md Use this command to view all available options and configurations for the 'sam build' command. ```bash sam build --help ``` -------------------------------- ### Initialize Serverless Application with Lambda Response Streaming Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/using-sam-cli-remote-invoke.md Use `sam init` to create a new serverless application. Select the 'Lambda Response Streaming' template and specify the desired runtime and project name. This sets up a basic project structure for response streaming. ```bash $ sam init You can preselect a particular runtime or package type when using the `sam init` experience. Call `sam init --help` to learn more. Which template source would you like to use? 1 - AWS Quick Start Templates 2 - Custom Template Location Choice: {{1}} Choose an AWS Quick Start application template 1 - Hello World Example ... 9 - Lambda Response Streaming ... 15 - Machine Learning Template: {{9}} Which runtime would you like to use? 1 - go (provided.al2) 2 - nodejs18.x 3 - nodejs16.x Runtime: {{2}} Based on your selections, the only Package type available is Zip. We will proceed to selecting the Package type as Zip. Based on your selections, the only dependency manager available is npm. We will proceed copying the template using npm. Would you like to enable X-Ray tracing on the function(s) in your application? [y/N]: {{ENTER}} Would 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]: {{ENTER}} Project name [sam-app]: {{lambda-streaming-nodejs-app}} ----------------------- Generating application: ----------------------- Name: lambda-streaming-nodejs-app Runtime: nodejs18.x Architectures: x86_64 Dependency Manager: npm Application Template: response-streaming Output Directory: . Configuration file: lambda-streaming-nodejs-app/samconfig.toml Next steps can be found in the README file at lambda-streaming-nodejs-app/README.md Commands you can use next ========================= [*] Create pipeline: cd lambda-streaming-nodejs-app && sam pipeline init --bootstrap [*] Validate SAM template: cd lambda-streaming-nodejs-app && sam validate [*] Test Function in the Cloud: cd lambda-streaming-nodejs-app && sam sync --stack-name {stack-name} --watch ``` -------------------------------- ### Install AWS SAM CLI using Installer Script Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.md Install the AWS SAM CLI using the installer script. This command assumes you have downloaded the .pkg file and are running it with administrator privileges. ```bash $ sudo installer -pkg {{path-to-pkg-installer}}/{{name-of-pkg-installer}} -target / installer: Package name is AWS SAM CLI installer: Upgrading at base path / installer: The upgrade was successful. ``` -------------------------------- ### Uninstall AWS SAM CLI on macOS (Package Installer) Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/manage-sam-cli-versions.md Commands to remove the AWS SAM CLI installation directory and its symlink on macOS when installed via the package installer. Adjust paths as necessary. ```bash $ {{sudo}} rm -rf {{/path-to}}/aws-sam-cli ``` ```bash $ {{sudo}} rm -rf {{/path-to-symlink-directory}}/sam ``` -------------------------------- ### Install AWS SAM CLI using Homebrew Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/manage-sam-cli-versions.md Install the AWS SAM CLI using the community-managed Homebrew installer. ```bash $ brew install aws-sam-cli ``` -------------------------------- ### Example .aws-sam Directory Structure Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-getting-started-hello-world.md This illustrates the typical structure of the `.aws-sam` directory created by the AWS SAM CLI after a successful build, highlighting key files and directories. ```text .aws-sam ├── build │ ├── HelloWorldFunction │ │ ├── __init__.py │ │ ├── app.py │ │ └── requirements.txt │ └── template.yaml └── build.toml ``` -------------------------------- ### Example Project Structure with samconfig.toml Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-config.md Illustrates the typical location of the `samconfig.toml` file within an AWS SAM project structure. ```text sam-app ├── README.md ├── __init__.py ├── events ├── hello_world ├── samconfig.toml ├── template.yaml └── tests ``` -------------------------------- ### Install AWS SAM CLI Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.md Run the installer with the '-applyChoiceChangesXML' flag to install the AWS SAM CLI using the specified custom location. ```bash $ installer -pkg {{path-to-pkg-installer}} \ -target CurrentUserHomeDirectory \ -applyChoiceChangesXML {{path-to-your-xml-file}} # Example output installer: Package name is AWS SAM CLI installer: choices changes file '{{path-to-your-xml-file}}' applied installer: Upgrading at base path {{base-path-of-xml-file}} installer: The upgrade was successful. ``` -------------------------------- ### Initialize with local file path Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/using-sam-cli-init.md Use the `--location` flag with a local file path to initialize a project from a custom template archive (e.g., a zip file). ```bash $ sam init --location {{/path/to/template.zip}} ``` -------------------------------- ### Get help for `sam remote test-event get` Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/using-sam-cli-remote-test-event.md Display the help information for the `get` subcommand of the `sam remote test-event` command to see all available options. ```bash $ sam remote test-event get --help ``` -------------------------------- ### Initialize with Bitbucket location Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/using-sam-cli-init.md Use the `--location` flag with a Bitbucket repository path to initialize a project from a custom template. ```bash $ sam init --location {{hg+ssh://hg@bitbucket.org/repo/template-name}} ``` -------------------------------- ### Configure SAM CLI Installation Directory Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-sam-cli.md Create an XML file to specify the custom installation directory for the AWS SAM CLI. Ensure the directory exists before running the installer. ```xml choiceAttribute customLocation attributeSetting {{path-to-my-directory}} choiceIdentifier default ``` -------------------------------- ### Check Finch Version on macOS Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-finch.md Verify the installed Finch version after installation. ```bash $ finch --version ``` -------------------------------- ### Verify Homebrew Installation Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/manage-sam-cli-versions.md Verify the AWS SAM CLI installation after using Homebrew. ```bash $ sam --version ``` ```text SAM CLI, version {{1.94.0}} ``` -------------------------------- ### sam local start-api Usage Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-cli-command-reference-sam-local-start-api.md This command starts a local API endpoint for testing your Lambda functions. Use options to configure its behavior. ```bash $ sam local start-api {{}} ``` -------------------------------- ### Install Docker on Amazon Linux 2023 Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/install-docker.md Installs Docker on Amazon Linux 2023. ```bash $ sudo yum install -y docker ``` -------------------------------- ### sam local start-api output with Terraform Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/using-samcli-terraform.md This output shows the process of preparing the Terraform application, generating metadata, and mounting the Lambda function for local testing. ```text $ sam local start-api --hook-name terraform Running Prepare Hook to prepare the current application Executing prepare hook of hook "terraform" Initializing Terraform application ... Creating terraform plan and getting JSON output .... Generating metadata file Unresolvable attributes discovered in project, run terraform apply to resolve them. Finished generating metadata file. Storing in... Prepare hook completed and metadata file generated at: ... Mounting HelloWorldFunction at http://127.0.0.1:3000/hello [GET] Mounting None at http://127.0.0.1:3000/hello [POST] You can now browse to the above endpoints to invoke your functions. You do not need to restart/reload SAM CLI while working on your functions, changes will be reflected instantly/automatically. If you used sam build before running local commands, you will need to re-run sam build for the changes to be picked up. You only need to restart SAM CLI if you update your AWS SAM template 2023-06-26 13:21:20 * Running on http://127.0.0.1:3000/ (Press CTRL+C to quit) ``` -------------------------------- ### Initialize a new SAM project with .NET 8 Native AOT Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/build-dotnet7.md Use the AWS SAM CLI to initialize a new project, selecting the .NET 8 runtime and a Native AOT template. ```bash sam init ``` -------------------------------- ### Verify the AWS SAM CLI package installer signature Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/reference-sam-cli-install-verify.md Verify the integrity of the AWS SAM CLI package installer using its signature file. A 'Good signature' message confirms the installer has not been tampered with. ```bash $ gpg --verify {{aws-sam-cli-linux-arm64.zip.sig aws-sam-cli-linux-arm64.zip}} ``` ```text gpg: Signature made Mon 19 May 2025 01:21:57 AM UTC using RSA key ID 4094ABB1BEDFDAB4 gpg: Good signature from "AWS SAM CLI Team " gpg: WARNING: This key is not certified with a trusted signature! gpg: There is no indication that the signature belongs to the owner! Primary key fingerprint: EF46 3E86 CA31 933B B688 CC1A 4094 ABB1 BEDF DAB4 ``` -------------------------------- ### Initialize with GitHub location Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/using-sam-cli-init.md Use the `--location` flag with a GitHub repository path to initialize a project from a custom template. ```bash $ sam init --location {{gh:aws-samples/cookiecutter-aws-sam-python}} ``` ```bash $ sam init --location {{git+sh://git@github.com/aws-samples/cookiecutter-aws-sam-python.git}} ``` -------------------------------- ### ProvisionedThroughput Example Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-property-simpletable-provisionedthroughputobject.md Example of how to configure provisioned throughput for a DynamoDB table in an AWS SAM template. ```yaml Properties: ProvisionedThroughput: ReadCapacityUnits: {{5}} WriteCapacityUnits: {{5}} ``` -------------------------------- ### Navigate to Application Directory Source: https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-getting-started-hello-world.md After initializing the application, change your current directory to the newly created application folder to access its files and run subsequent commands. ```bash $ cd sam-app ```