# This is the SAM template that represents the architecture of your serverless application # https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-template-basics.html # The AWSTemplateFormatVersion identifies the capabilities of the template # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/format-version-structure.html AWSTemplateFormatVersion: 2010-09-09 Description: >- Website & Mobile starter project # Transform section specifies one or more macros that AWS CloudFormation uses to process your template # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/transform-section-structure.html Transform: AWS::Serverless-2016-10-31 # Shared configuration for all resources, more in # https://github.com/awslabs/serverless-application-model/blob/master/docs/globals.rst Globals: Function: # The PermissionsBoundary allows users to safely develop with their function's permissions constrained # to their current application. All the functions and roles in this application have to include it and # it has to be manually updated when you add resources to your application. # More information in https://docs.aws.amazon.com/IAM/latest/UserGuide/access_policies_boundaries.html PermissionsBoundary: !Sub 'arn:${AWS::Partition}:iam::${AWS::AccountId}:policy/${AppId}-${AWS::Region}-PermissionsBoundary' Parameters: AppId: Type: String # Resources declares the AWS resources that you want to include in the stack # https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/resources-section-structure.html Resources: # Each Lambda function is defined by properties: # https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction # This is a Lambda function config associated with the source code: get-all-items.js getAllItemsFunction: Type: AWS::Serverless::Function Properties: CodeUri: ./ Handler: src/handlers/get-all-items.getAllItemsHandler Runtime: nodejs18.x MemorySize: 128 Timeout: 60 Description: A simple example includes a HTTP get method to get all items from a DynamoDB table. Policies: # Give Create/Read/Update/Delete Permissions to the SampleTable - DynamoDBCrudPolicy: TableName: !Ref SampleTable Environment: Variables: # Make table name accessible as environment variable from function code during execution SAMPLE_TABLE: !Ref SampleTable Events: Api: Type: Api Properties: Path: / Method: GET # Each Lambda function is defined by properties: # https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction # This is a Lambda function config associated with the source code: get-by-id.js getByIdFunction: Type: AWS::Serverless::Function Properties: CodeUri: ./ Handler: src/handlers/get-by-id.getByIdHandler Runtime: nodejs18.x MemorySize: 128 Timeout: 60 Description: A simple example includes a HTTP get method to get one item by id from a DynamoDB table. Policies: # Give Create/Read/Update/Delete Permissions to the SampleTable - DynamoDBCrudPolicy: TableName: !Ref SampleTable Environment: Variables: # Make table name accessible as environment variable from function code during execution SAMPLE_TABLE: !Ref SampleTable Events: Api: Type: Api Properties: Path: /{id} Method: GET # Each Lambda function is defined by properties: # https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlessfunction # This is a Lambda function config associated with the source code: put-item.js putItemFunction: Type: AWS::Serverless::Function Properties: CodeUri: ./ Handler: src/handlers/put-item.putItemHandler Runtime: nodejs18.x MemorySize: 128 Timeout: 60 Description: A simple example includes a HTTP post method to add one item to a DynamoDB table. Policies: # Give Create/Read/Update/Delete Permissions to the SampleTable - DynamoDBCrudPolicy: TableName: !Ref SampleTable Environment: Variables: # Make table name accessible as environment variable from function code during execution SAMPLE_TABLE: !Ref SampleTable Events: Api: Type: Api Properties: Path: / Method: POST # Simple syntax to create a DynamoDB table with a single attribute primary key, more in # https://github.com/awslabs/serverless-application-model/blob/master/versions/2016-10-31.md#awsserverlesssimpletable # DynamoDB table to store item: {id: , name: } SampleTable: Type: AWS::Serverless::SimpleTable Properties: PrimaryKey: Name: id Type: String ProvisionedThroughput: ReadCapacityUnits: 2 WriteCapacityUnits: 2