Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
Level
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

Deploy Lambda via Bitbucket Pipeline using AWS Lambda Deploy

I want to add environment variable with lambda while pushing from bitbucket. How we can achieve the same using

 

AWS Lambda Deploy Pipes

 

Please let me know, if there is a way to attach enviornment variable with lambda once they are pushed

1 answer

@Ashish Awasthifirstly, you need to create your lambda or update the lambda with environment variable. The only way I know - it can be done via sam template.

 

You can do this with sam deploy pipe. See example how to do this with sam deploy https://bitbucket.org/atlassian/aws-lambda-deploy/src/aa574370ffafa6bb2ede25ac37a5e6936cdafa05/bitbucket-pipelines.yml#lines-28 .

For this pipe you will provide sam template, where you mention variables section and put there variables you will need.

Here I provide with docs that you may need to do this in aws:

- https://docs.aws.amazon.com/serverless-application-model/latest/developerguide/sam-specification-template-anatomy-globals.html  - first example is that how you pass lambda environment variables to the template.yaml .  You can go basically with this doc and use basic examples from sam-deploy pipe https://bitbucket.org/atlassian/aws-sam-deploy/src/master/README.md

 

- BUT If you do not want to expose your environment variables (e.g., they are sensitive) in Bitbucket Cloud - use AWS embedded parameters for that  (  https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/parameters-section-structure.html ) like here:


Parameters:
TableName:
Type: String
......
your other setting for your lambda function
......
Globals:
Function: Runtime: nodejs12.x Timeout: 180 Handler: ... Environment: <---- your env variables Variables: TABLE_NAME: !Ref TableName  <----- here you refer to parameters

and our STACK_PARAMETERS advanced example , when using sam-deploy pipe.

Precisely, you will need advanced example with STACK_PARAMETERS in Advanced examples section (https://bitbucket.org/atlassian/aws-sam-deploy/src/master/README.md ) :

 

script:
  - pipe: atlassian/aws-sam-deploy:1.1.0
    variables:
      AWS_ACCESS_KEY_ID: $AWS_ID
      AWS_SECRET_ACCESS_KEY: $AWS_KEY
      AWS_DEFAULT_REGION: 'us-east-1'
      S3_BUCKET: 'my-s3-bucket'
      STACK_NAME: 'my-stack-name'
      SAM_TEMPLATE: 'sam_template.yaml' <------ your template yaml
      CAPABILITIES: ['CAPABILITY_AUTO_EXPAND']
      STACK_PARAMETERS: >
        [{
          "ParameterKey": "TableName", 
"ParameterValue": ${YOUR_SECRET_ENIRONMENT_VARIABLE} <----- your secured var here
}
]

 

I will repeat, If you don't actually need secret environment vars to pass, you can just hardcode environment variable in Environment section and not use Parameters tool.

But we recommend the safer and more flexible way to be able to secure your lambda environment.

 

After executing sam-deploy pipe with such template environment variable, lambda function should be created or updated with mentioned environment variables  in the template.

Hope , this explanation is not too vague.

But anyway contact us in the case of more questions or if something did not work.

 

Regards, Galyna

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Confluence

⚡️NEW Group for Confluence Cloud Admins

Calling all Confluence Cloud Admins!  We created a new Community Group to support your unique needs as Confluence admins. This is a group where you can ask questions, access resou...

91 views 2 7
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