This document is a work in progress, please add edits/updates!
If you are deploying a lambda for the first time you will need to follow these steps or the deploy will fail:
- preview the deploy using riffraff and uncheck all tasks except the
uploadLambda
one before hitting deploy as shown in this screenshot: - go back to the deploy screen and deploy as normal (all the tasks)
- set up continuous deployment for future deploys (optional)
Update 27/04/2024 - As an alternative to the process described above, for Typescript lambdas you can use the create-stack.sh
script in the root of the repo to build your lambda, upload the zip to S3 and then create the stack using your cloudformation.
eg. from the root of the repo run
./create-stack.sh my-new-lambda
We have a code generation script (using Hygen) which will generate a scaffold for new lambdas
with an API Gateway front end and a custom domain name. To use it run pnpm new-lambda
at the root of the repo, you will be prompted to
- provide a name for
your new lambda - the convention is to use a hyphenated name such as
my-new-lambda
. - decide whether to create an api key for your lambda - the default is to do so.
This will then carry out the following actions:
- create a new subdirectory of
\handlers
with the name of your new lambda - add a
package.json
ariff-raff.yaml
, atsconfig.json
and asrc\index.ts
file to this directory - add a new CDK lib definition for your new lambda and the related infrastructure into the
cdk\libs
directory - create a new instance of that lib in cdk.ts
- add the new project to ci-typescript.yml so that it is built in Github
You can test this has worked by pushing your branch and deploying to code (take note of important deployment note above). You should then be able to call your lambda with cUrl
curl --location 'https://my-new-lambda-code.membership.guardianapis.com/prod'
and receive a 200 response with the body 'Hello World'.
You can then go ahead and write your lambda in my-new-lambda\index.ts
- copy the sf-contact-merge lambda
- delete all the code from the handler that you don't need
- search and replace all sf-contact-merge in the code/packages/cfn with your chosen name
- change the ApiGatewayTargetDomainName for CODE and PROD to tbc.execute-api.eu-west-1.amazonaws.com
- push the branch and deploy to code
- look at the custom domain name that was created by the deploy
- look at the target domain name in the regional box (should start d-4765437.execute-api.eu-west-1.amazonaws.com or similar)
- edit the ApiGatewayTargetDomainName to point to the target domain name
- raise a PR with the PROD still showing tbc and get it merged
- deploy to prod with riff-raff (see steps below)
- follow the steps after "deploy to code" again in order to update the PROD domain name.
- set up a health check job in Runscope (optional)
IMPORTANT: The IntegrationHttpMethod
(between API Gateway with Lambda) needs to always be POST
- see https://stackoverflow.com/a/55457240/5205022 for more information
NOTE: If you make subsequent configuration changes to the API Gateway (even via CloudFormation) you may need to manually 'Deploy API' which can be done via the AWS Console (API Gateway > {gateway in question} > Resources > Actions ▼ > Deploy API)