aws-cdk: [aws-codepipeline] Parameter overrides cannot use Fn::GetArtifactAtt
I have been trying to create a deployment pipeline for Lambda function using CodePipeline. During development I noticed there is weird issue which does not allow me to use Fn::GetArtifactAtt in the parameterOverrides (1), because default JSON serializer forces to use Fn::Join which does not accept Fn::GetArtifactAtt.
I see it was noticed in #566, but for 0.22.0 (build 644ebf5) version it does not work for me.
import iam = require('@aws-cdk/aws-iam');
import codepipeline = require('@aws-cdk/aws-codepipeline');
import cloudformation = require('@aws-cdk/aws-cloudformation');
import codepipelineapi = require('@aws-cdk/aws-codepipeline-api');
const addDeployPrepareAction = (
id: string,
buildArtifact: codepipelineapi.Artifact,
props: {
stage: codepipeline.Stage,
stackName: string,
region: string,
changeSetName: string,
role: iam.Role
}
) => {
const { stackName, stage, region, changeSetName, role } = props
new cloudformation.PipelineCreateReplaceChangeSetAction(stage, id, {
stackName,
stage,
region,
role,
changeSetName,
runOrder: 1,
adminPermissions: false,
capabilities: cloudformation.CloudFormationCapabilities.NamedIAM,
parameterOverrides: {
'LambdaCodeZip': buildArtifact.objectKey,
'LambdaCodeBucket': buildArtifact.bucketName,
},
})
}
Expected (one of the possible solution):
ParameterOverrides: !Sub |
{
"LambdaCodeZip" : { "Fn::GetArtifactAtt" : [ "BuildOutput", "ObjectKey" ] },
"LambdaCodeBucket": { "Fn::GetArtifactAtt" : [ "BuildOutput", "BucketName" ] }
}
Actual:
ParameterOverrides:
Fn::Join:
- ""
- - '{"LambdaCodeZip":"'
- Fn::GetArtifactAtt:
- BuildOutput
- ObjectKey
- '","LambdaCodeBucket":"'
- Fn::GetArtifactAtt:
- BuildOutput
- BucketName
- '"}'
Error:
aws cloudformation validate-template --template-body file://pipeline.json
An error occurred (ValidationError) when calling the ValidateTemplate operation: Template Error: Encountered unsupported function: Fn::GetArtifactAtt Supported functions are: [Fn::Base64, Fn::GetAtt, Fn::GetAZs, Fn::ImportValue, Fn::Join, Fn::Split, Fn::FindInMap, Fn::Select, Ref, Fn::Equals, Fn::If, Fn::Not, Condition, Fn::And, Fn::Or, Fn::Contains, Fn::EachMemberEquals, Fn::EachMemberIn, Fn::ValueOf, Fn::ValueOfAll, Fn::RefAll, Fn::Sub, Fn::Cidr]
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 19 (9 by maintainers)
Commits related to this issue
- feat(cdk): treat the "fake" CFN intrinsics (Fn::GetArtifactAtt, Fn::GetParam) specially when stringifying JSON. Fn::GetArtifactAtt and Fn::GetParam are not really intrinsics, they're functions that c... — committed to skinny85/aws-cdk by skinny85 5 years ago
- feat(cdk): treat the "fake" CFN intrinsics (Fn::GetArtifactAtt, Fn::GetParam) specially when stringifying JSON. (#1605) Fn::GetArtifactAtt and Fn::GetParam are not really intrinsics, they're functio... — committed to aws/aws-cdk by skinny85 5 years ago
- followed suggestions on https://github.com/aws/aws-cdk/issues/1588#issuecomment-550502381 to save on some characters — committed to stelligent/mutato by 3p3r 4 years ago
I figured out what the issue is. I submitted a PR with the fix here.
A couple of things about that:
LambdaSourceBucketNameParameterandLambdaSourceObjectKeyParameter, are just the defaults. You can create your own:Hope this helps!
Adam
I don’t think this issue is solved. I’m facing it just right now.
This is how my code looks like:
This is the output when I run
cdk deploy '*':This is how the outputs from template looks like:
CDK version:
1.87.1 (build 9eeaa93)OS system: macOS Catalina 10.15.5