Files
swift-aws-lambda-runtime/Examples/LambdaFunctions
tomer doron 75d05ca954 docs cleanup (#91)
motivation: cleanup docs for oss

changes:
* add useful information in readme, with pointers to examples
* update ci setup and example to use latest tools
* update contributors list

Co-authored-by: Yim Lee <yim_lee@apple.com>
2020-05-28 12:19:19 -07:00
..
2020-05-07 08:56:31 -07:00
2020-05-28 12:19:19 -07:00
2020-05-07 08:56:31 -07:00

Lambda Functions Examples

This sample project is a collection of Lambda functions that demonstrates how to write a simple Lambda function in Swift, and how to package and deploy it to the AWS Lambda platform.

Deployment instructions using AWS CLI

Steps to deploy this sample to AWS Lambda using the AWS CLI:

  1. Login to AWS Console and create an AWS Lambda with the following settings:
  • Runtime: Custom runtime
  • Handler: Can be any string, does not matter in this case
  1. Build, package and deploy the Lambda
./scripts/deploy.sh

Note: This script assumes you have AWS CLI installed and credentials setup in ~/.aws/credentials.

Deployment instructions using AWS SAM (Serverless Application Model)

AWS Serverless Application Model (SAM) is an open-source framework for building serverless applications. This framework allows you to easily deploy other AWS resources and more complex deployment mechanisms such a CI pipelines.

Note: Deploying using SAM will automatically create resources within your AWS account. Charges may apply for these resources.

To use SAM to deploy this sample to AWS:

  1. Install the AWS CLI by following the instructions.

  2. Install SAM CLI by following the instructions.

  3. Build, package and deploy the Lambda

./scripts/sam-deploy.sh --guided

The script will ask you which sample Lambda you wish to deploy. It will then guide you through the SAM setup process.

      Setting default arguments for 'sam deploy'
  =========================================
  Stack Name [sam-app]: swift-aws-lambda-runtime-sample
  AWS Region [us-east-1]: <your-favourite-region>
  #Shows you resources changes to be deployed and require a 'Y' to initiate deploy
  Confirm changes before deploy [y/N]: Y
  #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]: Y
  Save arguments to samconfig.toml [Y/n]: Y

If you said yes to confirm changes, SAM will ask you to accept changes to the infrastructure you are setting up. For more on this, see Cloud Formation.

The sam-deploy script passes through any parameters to the SAM deploy command.

  1. Subsequent deploys can just use the command minus the guided parameter:
./scripts/sam-deploy.sh

The script will ask you which sample Lambda you wish to deploy. If you are deploying a different sample lambda, the deploy process will pull down the previous Lambda.

SAM will still ask you to confirm changes if you said yes to that initially.

  1. Testing

For the API Gateway sample:

The SAM template will provide an output labelled LambdaApiGatewayEndpoint which you can use to test the Lambda. For example:

curl <<LambdaApiGatewayEndpoint>>

Warning: This SAM template is only intended as a sample and creates a publicly accessible HTTP endpoint.

For all other samples use the AWS Lambda console.