Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Use pipline to update layer

MANI Adel
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
September 27, 2019

Hello, 

I am using bitbucket pipline to deploy my lambdas. For now everything is fine, except for deploying layers. 

in 2018 aws introduced layer for lambdas, mainly used to share a common code (conf, models, ...) between lambdas and also to create runtime environement for not supported langages. 

I have lambdas to manage users (nodejs + mongodb) : create user, login, activate user, update, ...

these lambdas are sharing the same model and configuration. So, I would like to avoid duplicating code, so I thought about creating layer. 

My problem is:

1/ How can I do to update my layer when I deploy my lambda (specify latest layer) ?

 

I am using (AWS Lambda deploy : v0.3.2maintained by Atlassian)

 

Thank you in advance for your help. 

 

Best regards

Adel MANI

 

 

2 answers

0 votes
Yadvendra_Singh January 8, 2020

Hi @Alexander Zhukov

I tried the same config but failed. just removed the account number for security.

 

here is my config file 

----------------------------

{"Layers":

    [

        { "Arn": "arn:aws:lambda:eu-west-1:xxxxxxxxxxx:layer:ap-mail-node-pgpool-1:22", "CodeSize": 229879 }

    ]

}

---------------------------------------

function update part works just file but while updating config it fails

here is the error log

INFO: Updating Lambda function configuration.aws lambda update-function-configuration --function-name ap-mail-ds1-scs-1 --cli-input-json {"Layers": [ { "Arn": "arn:aws:lambda:eu-west-1:xxxxxxxxxxx:layer:ap-mail-node-pgpool-1:22", "CodeSize": 229879 } ]}Parameter validation failed:Invalid type for parameter Layers[0], value: {u'CodeSize': 229879, u'Arn': u'arn:aws:lambda:eu-west-1:xxxxxxxxxxx:layer:ap-mail-node-pgpool-1:22'}, type: <type 'dict'>, valid types: <type 'basestring'>✖ Failed to update Lambda function configuration.

0 votes
Alexander Zhukov
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
October 2, 2019

Hi @MANI Adel . If you wan't to just add an existing layer to your lambda function, you should create a function configuration json file an reference it in the FUNCTION_CONFIGURATION variable. The pipe will update the function configuration to include the layers.


Example function-configuration.json

{"Layers": 
[
{ "Arn": "arn:aws:lambda:us-east-2:123456789012:layer:my-layer:3", "CodeSize": 169 },
{ "Arn": "arn:aws:lambda:us-east-2:210987654321:layer:their-layer:2", "CodeSize": 169 }
]
}

 Example pipe configuration:

script:
  - pipe: atlassian/aws-lambda-deploy:0.4.1
    variables:
      AWS_ACCESS_KEY_ID: $AWS_ACCESS_KEY_ID
      AWS_SECRET_ACCESS_KEY: $AWS_SECRET_ACCESS_KEY
      AWS_DEFAULT_REGION: $AWS_DEFAULT_REGION
      FUNCTION_NAME: 'my-lambda-function'
      COMMAND: 'update'
      ZIP_FILE: 'my-function-code.zip'
FUNCTION_CONFIGURATION: 'function-configuration.json'

 

Note, that updating or creating a function layer is not supported in the pipe yet. 

MANI Adel
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
October 2, 2019

Hi @Alexander Zhukov
Thank you for replying my request. 

My question was not clair, I was looking for the way how to deploy an update or publish of layer (publish-layer-version)

I solved this problem by creating aws_nodejs docker image and lauching the the following CLI command : 

 script:  
-
aws configure set default.region $AWS_DEFAULT_REGION
-
aws configure set aws_access_key_id $AWS_ACCESS_KEY_ID
-
aws configure set aws_secret_access_key $AWS_SECRET_ACCESS_KEY
-
aws lambda publish-layer-version --layer-name Layer_01 --compatible-runtimes nodejs nodejs10.x nodejs8.10 --zip-file fileb://nodejs.zip --region $AWS_DEFAULT_REGION

 

Thank you very much for taking in consideration my request. 

 

Best regards

Adel 

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events