- Newest
- Most votes
- Most comments
Hello,
I understand that you would like to know how versioning can be done with AWS CDK for EC2 Image Builder.
In order to achieve this make sure to specify the version in the 'sematicVersion' field when creating a new version of component/recipe. Also, please note that 'semanticVersion' is a required field. Hence please check on how the recipe/component is being updated, is it by specifying same version or no version.
The following are few reference links relevant to your use case: [+] https://docs.aws.amazon.com/imagebuilder/latest/userguide/create-image-recipes.html [+] https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/imagebuilder/client/create_component.html#
I hope the above information helps!
Since there is no real support for auto incrementing the versions, the way we decided to do it was completely random versions. That way we at least won't have conflicts deploying.
class RecipeComponent extends imagebuilder.CfnImageRecipe {
constructor(scope: cdk.Stack, id: string, props: Omit<imagebuilder.CfnImageRecipeProps, "version">) {
const hash = crypto.createHash("md5")
.update(JSON.stringify(props))
.update(id)
.digest();
let paddedBuffer;
if (hash.length % 4 !== 0) {
const paddingLength = 4 - (hash.length % 4);
paddedBuffer = Buffer.concat([hash, Buffer.alloc(paddingLength)]);
} else {
paddedBuffer = hash;
}
let xorResult = 0;
for (let i = 0; i < paddedBuffer.length; i += 4) {
const int = paddedBuffer.readUInt32LE(i);
xorResult ^= int;
}
const absoluteVersion = Math.floor(Math.abs(xorResult) / 2);
super(scope, id, { ...props, version: `${absoluteVersion}.0.0` });
}
}
answered 2 years ago
Relevant content
- AWS OFFICIALUpdated 2 years ago
