How to Increase Your Python Aws Cdk Lambda Development Speed by Testing Locally with AWS SAM

Cross-post from: Medium This article explains how to locally test, with AWS SAM (Serverless Application Model), a Lambda function + API Gateway created with AWS CDK (Cloud Development Kit). Python AWS CDK and SAM are a match made in heaven, or at least a match made in the cloud. This example uses the AWS CDK in Python. Using Python AWS CDK and SAM When using AWS CDK for your infrastructure as code, it can be a pain to figure out how to efficiently test your Lambda functions....

September 17, 2021 · 4 min · chart

AWS CDK: Avoiding CDK stack dependency errors on updates

Have you encountered an error such as the one below? Export my-stack-1:ExportsOutputRefMyResource6724B74E921810D3 cannot be deleted as it is in use by my-stack-2 This is because: A resource created by my-stack-1.py has created an export my-stack-2.py is using this export in one of it’s resources You are attempting to change or remove the resource in my-stack-1.py, altering the export How can this error be worked around? One method would be to tear down my-stack-2, update my-stack-1, then re-deploy my-stack-2....

February 1, 2021 · 1 min · chart

AWS CDK: Place a Lambda function in specific subnets

I struggled for a while today to figure out how to place a lambda function inside of a given SubnetType of a VPC generated in the same CDK stack. To specify subnets for a lambda function it needs a SubnetSelection object passed in. I expected to find a method of ec2.VPC() which would give me an output with the type SubnetSelection but this doesn’t exist. After some reading of other people’s posts online I found an example which showed what I needed to do:...

January 27, 2021 · 1 min · chart

AWS CDK: Python Tips, Tricks, and Examples

Examples Official CDK Python Examples: https://github.com/aws-samples/aws-cdk-examples/tree/master/python Unofficial CDK best practices: https://github.com/kevinslin/open-cdk Basics Read the docs! Run the following command to open the CDK docs in your browser: cdk docs Set the deployment region In the app.py in the root of your CDK construct: add env={‘region’: ‘us-east-2’} to your ConstructStack(…). At time of writing this is on line 9 by default. It should look something like this: app = core.App() MyConstructStack(app, "my-construct", env={'region': 'us-east-2'}) Install new packages When working with a new services you may need to install them with a command similar to the one below:...

January 11, 2021 · 2 min · chart

Learning the AWS CDK

CloudFormation written in Python? Yes! After using the CDK for a bit, I believe it will be replacing CloudFormation for most AWS IaC in the coming years. The CDK is a layer of abstraction built on top of CloudFormation(CF). It allows you to write a condensed, but more powerful form of CF in one of several programming languages(JavaScript, TypeScript, Python, Java, and C#). You utilize AWS Constructs to more concisely deploy infra....

January 11, 2021 · 1 min · chart

Fix error sam deploy unable to locate credentials using AWS SAM with AWS CLI v2 SSO

I got this error sam deploy unable to locate credentials when trying to use AWS SAM with AWS CLIv2 SSO. Error: Unable to upload artifact myAPIName referenced by CodeUri parameter of myAPIName resource. Unable to locate credentials In summary, the fix is to update SAM. The issue: sam deploy unable to locate credentials First, I signed into AWS SSO with the profile I wanted to use. $ aws sso login --profile new-dev-sso Then, I tried to run sam deploy....

October 7, 2020 · 1 min · chart