...
configuration of the properties e.g. Cloud account, and CLI path.
cloning the code and environment file from the Git repository.
create the docker image and push it to the AWS ECR registry.
perform the deployment using the newly created image present at AWS ECR.
verify the deployment.
Checklist
...
We can see the details of ECR registry.
...
Configure Container
...
Account
Configure AWS Container Account under Topology. FlexDeploy will connect to the AWS private container registry and push the image.
...
Docker Registry Token/password needs to be kept hidden. To update the same click on the pencil icon as shown below
next update the AWS IAM user key under Secret Text. This is to make sure no one else can retrieve the password
...
Git
...
Repository Structure
The Git repository should be a docker based application. Dockerfile should be present in application to build the image and environment variables file to add the variables.
The Sample Git repository structure is given below:
...
Pre-requisite
Configure IAM User
To access the Lambda Function we need to create an AWS IAM account with required permissions. To create the AWS IAM user navigate to the AWS Identity and Access Management (IAM) service page, and click on the Add users option. Next assign the required permission to access the Lambda Function. Once user is created, AWS secret key can be generated, this key we have to configure in Cloud account.
For more information about IAM user please ref. IAM users - AWS Identity and Access Management
...
CLI Installation
AWS CLI should be installed in the m/c where the plugin is to be executed. Preferably add AWS CLI path in m/c classpath.
Build and Deploy Workflows
Navigate to the Workflows tab and create a workflow using the “+”(Click to create new Workflow) button as highlighted below.
...
Next, create one Build and Deploy workflow as shown below. The workflow Type field defines the type of workflow.
Build Workflow
Navigate to the Workflows
Select the “+” button from the left-hand pane to create a new workflow
...
Deploy Workflow
navigate to the Workflows
Select the “+” button from the left-hand pane to create a new workflow
...
The Workflow Group and Subgroup define the folder hierarchy. Once both workflows are created it should look like the below. No constraint on workflow or folder naming convention.
...
The steps of the workflow execution can be configured through the Workflow Definition section.
...
Below given is a sample build workflow to copy the file from Git repository.
...
Step-i: Clone Git Repository
This step will clone the Git repository codebase into the project execution working directory. The Git URL will be retrieved from Source Control configured under Project Configuration.
...
Step-ii: Copy the environment file
The below step will copy the environment file to the artifact. Also check the Produces Artifact option to save the files as artifact so that can be used from Deploy workflow.
...
Below given is a sample workflow to build and push image to AWS ECR and then use this Image to update Lambda function code.
...
Step-i: Clone Git Repository
This step will clone the Git repository codebase into the project execution working directory. The Git URL will be retrieved from Source Control configured under Project Configuration.
...
Step-ii: Build and Push the docker image to AWS private container registry
Below given is the Docker plugin(buildImage operation) configurations. The below step will build and push docker image to AWS private container registry.
...
The plugin operation by default would look for Dokerfile under TEMP directory. In case the same exist in some other folder, relative path has to be specified from TEMP directory.
Step-iii:
...
updateLambdaFunctionCode
This step will deploy Lambda function code, and also publish the function version. We are setting function version variable, which we will use in upsert lambda operation.
...
In above configuration using following Inputs.
Input Name | Input Code | Type | Required | Description |
Additional Arguments | FDAWS_LAMBDA_INP_ADD_ENV_VAR_ADDITIONAL_ARG | String | No | Literal key and value pairs. e.g. --region=us-east-1 And for boolean type arguments give the option without any value. e.g --publish --debug |
Environment Variables | FDAWS_LAMBDA_INP_ENV_VAR | String | No | Environment Variables in acceptable format. |
Publish new version | FDAWS_LAMBDA_INP_PUBLISH_VERSION | Boolean | No | Select to publish a new version. Default value is false. |
Project Configuration
Navigate to the Project tab and create a Project with a logical name(AWS Deploy Lambda Function Using AWS ECR)
...
Configure the Build and Deploy workflow that has been created in previous steps as shown below.
...
Source Control
Configure the Source SCM repository under Source Control as shown below.
...
To configure Project specific Source Control one first need to navigate to the Project Configuration tab.
Next, expand the SOURCE CONTROL option from the left-hand pane.
Select the appropriate Source Control Type
Configure Source Repository. For detailed steps of Source Control configuration please refer to Configure Source Control in FlexDeployProject Properties
Project Properties
...
Lambda Function name: Name of the lambda function to deploy the code, if lambda function name is not given S3 key name will be use as function name.
Environment Variable File Path: Path of the file which contains list of the environment variables.
Please refer to the document for more details about Lambda function name and Environment Variable File path . AWS Lambda - Environment Variable File and zip File location options
KMS detail: Key Id or Key ARN details, both are accepted. Please refer to the document for more details. AWS Key Management Service - AWS Key Management Service
URI of a container Image: URI of a container image in the Amazon ECR registry.
Docker Image Name: The name of the docker image, including the repository if desired. i.e. foo/bar or bar.
Docker Image Tag: The tag of the docker image. For example: 1.2.3.
Target Properties
Select Topology from the menu and then select Targets. Select the target group and environment, provide the properties detail, according to the description.
Properties | Mandatory field | Description |
Cloud Account | Optional | Select the Cloud Account to connect the Lambda Function. |
CLI Path | Optional | Directory where Cloud CLI is installed. |
AWS Region | Optional | Value of the AWS Region. |
Below given are the environment-specific values which need to be updated.
...
Cloud Account
The AWS Cloud account needs to be set here from the drop-down. It will show all Cloud Accounts configured under Topology, which we have already mentioned earlier.
...
CLI Path
AWS CLI path can be set as environment property, if it’s not set then by default plugin will check for CLI in system classpath.
...
Override Properties at Project Level
Let assume a scenario, where we want to change Cloud account for any specific project. Apart from setting at environment level, it can also be set at project properties by using Override Property. Please check below mentioned steps.
Navigate to the Project Configuration tab as shown above.
Next, select the PROPERTIES option from the left-hand pane.
Click on the OVERRIDE option.
Select the Cloud Account option from Property.
Select the Environment from the drop down list.
Select the Target Group from the drop down list.
...
Build and Deploy Execution
For detailed steps on how to perform build and deploy, please refer to document. Deploy through FlexDeploy for AWS plugin
After Deploy Execution
Once the build and push image operation is done, we can see the details in the ECR registry.
...
Using the above image the deploy operation is executed, we can see the details of the image in the AWS console.
...
We can verify the deploy version from the plugin output and AWS console.
...
Container Image Settings
The following are common container image settings.
ENTRYPOINT – Specifies the absolute path to the entry point of the application.
CMD – Specifies parameters that we want to pass in with ENTRYPOINT.
WORKDIR – Specifies the absolute path to the working directory.
ENV – Specifies an environment variable for the Lambda function.
For more information about how Docker uses the container image settings, see ENTRYPOINT in the Dockerfile reference on the Docker Docs website. For more information about using ENTRYPOINT and CMD, see Demystifying ENTRYPOINT and CMD in Docker on the AWS Open Source Blog. We can override these configurations using the addLambdaEnvironmentVariables operation.
Example to override Image configuration using the addLambdaEnvironmentVariables operation.
...
Check Image Configuration information from the AWS console.
...
Please refer to the link for more information about docker cmd and entrypoint https://phoenixnap.com/kb/docker-cmd-vs-entrypoint