Deploying a Flow as a Lambda Function on AWS
After you have created the flow, you can deploy it as a Lambda function on AWS.
Note the following points:
-
The flow must be configured with the ReceiveLambdaInvocation trigger.
-
If the execution role name is not provided in the ReceiveLambdaInvocation trigger, then the Lambda function is created with the default AWSLambdaBasicExecutionRole role. It has the following Amazon CloudWatch permissions:
-
Allow: logs:CreateLogGroup -
Allow: logs:CreateLogStream -
Allow: logs:PutLogEvents
If a non-existing execution role is provided, then the user whose AWS credentials are used in the AWS connection should have the following permissions:
-
iam:CreateRole -
sts:AssumeRole
To deploy a Flogo app as a Lambda function, user role can have access to following
AWSLambda_FullAccesspolicy which has all the required access. -
To deploy a flow as a Lambda function on AWS:
- Procedure
- Build your
Flogo app (
<myApp>) with theLinux/amd64target. This is because Lambda deployments are Linux-based and building the binary forLinux/amd64generates the appropriate artifact to deploy in your AWS Lambda function. Refer to Building the App for details on how to build an app. - Add execution permission to the native
Linux/amd64executable file that you built. Runchmod +x <myApp>-linux_amd64 - You can deploy the
<myApp>-linux_amd64in one of two ways:If you are using a Linux environment to design, build, and deploy your apps, you can directly run the following command:<LambdaTriggerBinary> --deploy lambda --aws-access-key <secret_key>
For example,myApp-Linux64 --deploy lambda --aws-access-key xxxxxxxxxNote: Ensure that theThis approach of deploying to AWS Lambda works only on Linux platforms.aws-access-keyis identical to the one configured in the Flogo UI for the selected AWS Connection. This is used for validation with theaws-access-keyconfigured as part of the AWS Connection within the UI and the value provided here does not overwrite theaws-access-keyused while designing the app.If you are using a non-Linux environment to design, build, and deploy apps, then use this approach:- Build your Flogo app
(<myApp>)with theLinux/amd64target. - Rename the Flogo executable file to bootstrap. This is mandatory per new
provided.al2andprovided.al2023runtimes. - Compress the executable file and rename it to
<myFunctionName>.zip. - From the AWS Lambda UI, create a Lambda function with Amazon Linux 2023 runtime.
- Create a role or attach an existing role in the Execution role.
- Click Create function.
- Go to Code source, click Upload from and upload the compressed file.
After successful deployment, the Lambda function is created in the AWS Lambda console.To override app properties used in a Lambda app during runtime, create a.propertiesor.jsonfile containing the properties and their values to override, then use the command:./<Lambda-app-name> --deploy --env-config <app-property-file-name>.properties
For example:./MyLambdaApp --deploy --env-config MyLambdaApp-env.properties
where MyLambdaApp is the Lambda app name andMyLambdaApp-env.propertiesis the properties file name.
All properties in the.propertiesor.jsonfile are passed to Lambda as environment variables. - Build your Flogo app
Deploying a Flow as a Lambda Function on AWS using AWS CLI
- Procedure
Build your Flogo App (
<myApp>) with theLinux/amd64target. This is because Lambda deployments are Linux-based and building the binary forLinux/amd64generates the appropriate artifact to deploy in your AWS Lambda function.Rename the Flogo executable to bootstrap. This is mandatory as per new
provided.al2andprovided.al2023runtimes.Compress the executable file and rename it to
myFunction.zip.Run the AWS CLI:
aws lambda create-function --function-name myFunction \ --runtime provided.al2023 --handler bootstrap \ --architectures x86_64 \ --role arn:aws:iam::111122223333:role/lambda-ex \ --region us-west-2 \ --zip-file fileb://myFunction.zip