You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Use the `invoke-function` command to invoke the function. You can pass a well-formed JSON payload as input to the function. The payload must be encoded in base64. The CLI returns the status code and stores the response in a file.
@@ -624,14 +632,130 @@ aws iam delete-role --role-name lambda_basic_execution
624
632
625
633
### Deploy your Lambda function with AWS Serverless Application Model (SAM)
626
634
627
-
TODO
635
+
AWS Serverless Application Model (SAM) is an open-source framework for building serverless applications. It provides a simplified way to define the Amazon API Gateway APIs, AWS Lambda functions, and Amazon DynamoDB tables needed by your serverless application. You can define your serverless application in a single file, and SAM will use it to deploy your function and all its dependencies.
628
636
629
-
#### Create the function
637
+
To use SAM, you need to [install the SAM CLI](https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/serverless-sam-cli-install.html) on your machine. The SAM CLI provides a set of commands to package, deploy, and manage your serverless applications.
630
638
631
-
#### Invoke the function
639
+
Use SAM when you want to deploy more than a Lambda function. SAM helps you to create additional resources like an API Gateway, an S3 bucket, or a DynamoDB table, and manage the permissions between them.
640
+
641
+
#### Create the function
642
+
643
+
When using SAM, you describe the infrastructure you want to deploy in a YAML file. The file contains the definition of the Lambda function, the IAM role, and the permissions needed by the function. The SAM CLI uses this file to package and deploy your function.
644
+
645
+
You can create a SAM template to define a REST API implemented by AWS API Gateway and a Lambda function with the following command
646
+
647
+
```sh
648
+
cat <<EOF > template.yaml
649
+
AWSTemplateFormatVersion: '2010-09-09'
650
+
Transform: AWS::Serverless-2016-10-31
651
+
Description: SAM Template for APIGateway Lambda Example
652
+
653
+
Resources:
654
+
# Lambda function
655
+
APIGatewayLambda:
656
+
Type: AWS::Serverless::Function
657
+
Properties:
658
+
# the directory name and ZIP file names depends on the Swift executable target name
The Lambda function must accept an APIGateway v2 JSON payload as input parameter and return a valid APIGAteway v2 JSON response. See the example code in the [APIGateway example README file](Examples/APIGateway/README.md).
680
+
681
+
To deploy the function with SAM, use the `sam deploy` command. The very first time you deploy a function, you must use the `--guided` flag to configure the deployment. The command will ask you a series of questions to configure the deployment.
682
+
683
+
684
+
Here is the command to deploy the function with SAM:
685
+
686
+
```sh
687
+
# start the first deployment
688
+
sam deploy --guided
689
+
690
+
Configuring SAM deploy
691
+
======================
692
+
693
+
Looking for config file [samconfig.toml] : Not found
694
+
695
+
Setting default arguments for'sam deploy'
696
+
=========================================
697
+
Stack Name [sam-app]: APIGAtewayLambda
698
+
AWS Region [us-east-1]:
699
+
#Shows you resources changes to be deployed and require a 'Y' to initiate deploy
700
+
Confirm changes before deploy [y/N]: n
701
+
#SAM needs permission to be able to create roles to connect to the resources in your template
702
+
Allow SAM CLI IAM role creation [Y/n]: y
703
+
#Preserves the state of previously provisioned resources when an operation fails
704
+
Disable rollback [y/N]: n
705
+
APIGatewayLambda has no authentication. Is this okay? [y/N]: y
0 commit comments