I have the following aws cli code in my project's makefile trying to deploy my troposphere cf template:
aws cloudformation deploy \
--template-file params/batch.json \
--stack-name $(STACK_NAME) \
--parameter-overrides file://params/$(ENV).json \
--capabilities CAPABILITY_NAMED_IAM \
--output json && \
aws cloudformation wait stack-create-complete \
--stack-name $(STACK_NAME)
I am trying to wait for the template to complete and deploy. Even so, it gets stuck in review_in_progress. Not sure if it is just a template issue or I also have to execute the changeset as I am only creating it.
Related
I have a CodePipeline configured with my single GitHub repo to trigger build & deploy on any commit.
My repo contains dozens of individual lambda functions.
The pre_build step does a full clean & restore. Then in the build step, I have a long list of commands like this:
- dotnet build -c Debug
- cd folder1
- dotnet lambda deploy-function --configuration Debug --region $Region --config-file aws-lambda-tools-test.json
- cd ../folder2
- dotnet lambda deploy-function --configuration Debug --region $Region --config-file aws-lambda-tools-test.json
- cd ../folder3
- dotnet lambda deploy-function --configuration Debug --region $Region --config-file aws-lambda-tools-test.json
My question is, is there any way for me to execute these deployments in parallel?
Before I have Lambda version and alias, based on the API update-function-code I can successfully deploy by
aws lambda update-function-code --function-name myFunction --zip-file fileb://archive.zip
After I added version and alias, I have Lambda version
$LATEST (default)
1
2
and alias
staging (point to version 1)
prod (point to version 2)
I try to deploy to staging (version 1),
1st Try
aws lambda update-function-code --function-name arn:aws:lambda:us-west-2:123456789000:function:myFunction:staging --zip-file fileb://archive.zip
gave error
Current operation does not support
versions other than $LATEST. Please set the version to $LATEST or do
not set a version in your request.
2nd Try
aws lambda update-function-code --function-name myFunction --zip-file fileb://archive.zip --s3-object-version 1
or
aws lambda update-function-code --function-name myFunction --zip-file fileb://archive.zip --s3-object-version staging
gave error
Please do not provide other FunctionCode
parameters when providing a ZipFile.
How to use AWS CLI to deploy lambda function to specific alias or version correctly? Thanks
Okay so assuming you already managed to deploy your lambda with this command :
aws lambda update-function-code --function-name $FUNCTION_NAME --zip-file fileb://lambda.zip
And that you have created 2 versions with 2 alias (staging an prod).
Now you just need to publish to the rigth version :
VERSION=1
aws lambda update-alias --function-name $FUNCTION_NAME --name staging --function-version $VERSION
VERSION=2
aws lambda update-alias --function-name $FUNCTION_NAME --name prod --function-version $VERSION
If you want to go one step further you can bind the last deployment to the latest version. So first you need to retrieve the latest version and for this I use jq but feel free to use whatever you want, and then update with this version.
VERSION=$(aws lambda publish-version --function-name $FUNCTION_NAME | jq -r .Version)
aws lambda update-alias --function-name $FUNCTION_NAME --name staging --function-version $VERSION
Here is the update-alias documentation.
And here is the publish-version documention.
based on AWS documentations
A published version is immutable. That is, you can't change the code or configuration information.
so you need to publish a new version of your function and then update the alias to point to the newly created version.
I want to create a jenkins job that will publish a new AWS lambda version and update existing alias to new version just created.
I already have prod alias created in AWS Lambda.
Now i would i like to publish a new version and the update prod alias to point to new version.
There is walkthrough shows how to do it using AWS CLI. So here are the corresponding steps
1>Publish a new version of the Lambda function.
aws lambda publish-version --function-name helloworld
2>Update prod alias to latest version.
aws lambda update-alias --function-name helloworld function-version 2 --name prod
ISSUE
In Jenkins i will have to execute these commands as windows batch command
But i am not able to understand how do i dynamically pass the version number that was created by publish-version command in step 1, to update-alias command in step 2?
You can use below aws CLI command in the execute shell.
VERSION=$(aws lambda publish-version --function-name helloworld | jq -r .Version)
aws lambda update-alias --function-name helloworld --name prod --function-version $VERSION
When attempting to update a cloudformation stack in the aws cli:
aws --profile dev cloudformation update-stack --stack-name mystackname --template-body file://events-list.yaml
I get the following error
An error occurred (ValidationError) when calling the UpdateStack operation: UpdateStack cannot be used with templates containing Transforms.
Because I am using the AWS Serverless transform for lambda function deployments
Transform: 'AWS::Serverless-2016-10-31'
Is there a CLI way to execute this stack update or am I going to have to work on my APM in the GUI.
You can use deploy instead of update-stack:
aws cloudformation deploy \
--template-file serverless-output.yaml \
--stack-name new-stack-name \
--capabilities CAPABILITY_IAM
This command is necessary because Transforms need to be applied using change sets, which the deploy command automates for you. Refer to Working with Stacks that Contain Transforms for further discussion:
To create or update a stack with transforms, you must create a change set, and then execute it. A change set describes the actions AWS CloudFormation will take based on the processed template. During processing, AWS CloudFormation translates AWS SAM syntax into syntax that is defined by the transform. Processing can add multiples resources that you might not be aware of. For example, the specialized AWS::Serverless::Function resource adds an AWS Identity and Access Management (IAM) execution role and a Lambda function.
To ensure that you're aware of all of the changes introduced by transforms, AWS CloudFormation requires you to use change sets. [...]
If you use the AWS CLI, you can use the package and deploy commands to reduce the number of steps for launching stacks with transforms.
Try with deploy instead of update-stack
aws cloudformation deploy \
--template-file serverless-output.yaml \
--stack-name new-stack-name \
--capabilities CAPABILITY_IAM
To migrate from cedar to cedar-14 the docs says to first to a heroku stack:set cedar-14 and then the app will be migrated on the next git push.
The problem is that we are not using buildpacks but instead build our own slug which we publish through the heroku API.
Is there a way to trigger the migration without pushing to the heroku git repo?
To change the stack using the build API you need to send the stack as part of the Slug create post call.
e.g
local response=`curl -X POST \
-H 'Content-Type: application/json' \
-H 'Accept: application/vnd.heroku+json; version=3' \
-d { \
"process_types": { \
"web": "java $JAVA_OPTS -Djetty.port=$PORT -jar target/dependency/jetty-runner.jar --config jetty.xml target/xxxx.war" \
}, \
"stack": "cedar-14" \
} \
-n https://api.heroku.com/apps/EXAMPLE_APP/slugs`
This will change your stack!
NOTE: You need to include the correct JVM when creating the slug