It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Use pipline to update layer

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

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. 

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 

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.

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Bitbucket Pipelines

What We Learned When We Researched Open Source Vulnerabilities in 7 Popular Coding Languages

...hey are a part of us, shaping how we interact with the world around us. The same holds true for programming languages when we think about how different kinds of vulnerabilities raise their heads in t...

1,027 views 0 3
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you