(aws-cdk/aws-ecs): Unable to construct ContainerImage from tarball.
See original GitHub issueWhen trying to load a Docker image from a tarball, I get the following error:
/Users/nathan/repo/hello-ecs/node_modules/@aws-cdk/core/lib/stack-synthesizers/legacy.ts:114
throw new Error(`LegacyStackSynthesizer does not support this type of file asset: ${JSON.stringify(asset)}`);
^
Error: LegacyStackSynthesizer does not support this type of file asset: {"sourceHash":"75a7c80405856df9ef59fdb60715cca57a0e614cd81231abf0bb80213bb4cdef","executable":["sh","-c","docker load -i asset.75a7c80405856df9ef59fdb60715cca57a0e614cd81231abf0bb80213bb4cdef.tar | sed \"s/Loaded image: //g\""]}
at LegacyStackSynthesizer.doAddDockerImageAsset (/Users/nathan/repo/hello-ecs/node_modules/@aws-cdk/core/lib/stack-synthesizers/legacy.ts:114:15)
at LegacyStackSynthesizer.addDockerImageAsset (/Users/nathan/repo/hello-ecs/node_modules/@aws-cdk/core/lib/stack-synthesizers/legacy.ts:82:19)
at HelloEcsStack.addDockerImageAsset (/Users/nathan/repo/hello-ecs/node_modules/@aws-cdk/core/lib/stack.ts:360:29)
at LegacyStackSynthesizer.addDockerImageAsset (/Users/nathan/repo/hello-ecs/node_modules/@aws-cdk/core/lib/stack-synthesizers/legacy.ts:86:25)
at new TarballImageAsset (/Users/nathan/repo/hello-ecs/node_modules/@aws-cdk/aws-ecr-assets/lib/tarball-asset.ts:50:40)
at Object.bind (/Users/nathan/repo/hello-ecs/node_modules/@aws-cdk/aws-ecs/lib/container-image.ts:44:23)
at new ContainerDefinition (/Users/nathan/repo/hello-ecs/node_modules/@aws-cdk/aws-ecs/lib/container-definition.ts:214:36)
at FargateTaskDefinition.addContainer (/Users/nathan/repo/hello-ecs/node_modules/@aws-cdk/aws-ecs/lib/base/task-definition.ts:360:12)
at new ApplicationLoadBalancedFargateService (/Users/nathan/repo/hello-ecs/node_modules/@aws-cdk/aws-ecs-patterns/lib/fargate/application-load-balanced-fargate-service.ts:69:45)
at new HelloEcsStack (/Users/nathan/repo/hello-ecs/lib/hello-ecs-stack.ts:13:5)
Subprocess exited with error 1
Reproduction Steps
- Follow this tutorial: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/tutorial-ecs-web-server-cdk.html
- Replace
hello-ecs-stack.ts
with:
import * as path from 'path';
import * as cdk from '@aws-cdk/core';
import * as ecs from '@aws-cdk/aws-ecs';
import * as ecsp from '@aws-cdk/aws-ecs-patterns';
export class HelloEcsStack extends cdk.Stack {
constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
super(scope, id, props);
const tarballPath = path.join(__dirname, 'alpine.tar')
console.log('tarballPath: ', tarballPath)
new ecsp.ApplicationLoadBalancedFargateService(this, 'NathanTestWebServer', {
taskImageOptions: {
image: ecs.ContainerImage.fromTarball(tarballPath),
},
publicLoadBalancer: true
});
}
}
- Create tar of docker image. I used
docker save alpine/git -o lib/alpine.tar
. - run
cdk list
What did you expect to happen?
It would push the alpine image to ECR.
What actually happened?
It errored.
Environment
- **CDK CLI Version :1.116.0
- Framework Version:
- **Node.js Version:v16.0.0
- **OS :macOS Catalina
- **Language (Version):TypeScript (3.8.3)
Other
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
aws-cdk/aws-ecs module - AWS Documentation
This package contains constructs for working with Amazon Elastic Container Service (Amazon ECS). Amazon Elastic Container Service (Amazon ECS) is a fully ...
Read more >Hey CDK, how can I use a tarball as Docker image asset?
With assets, the AWS CDK provides an easy way to build Docker images based ... to use tarballs as source for CDK's container...
Read more >awslabs/aws-cdk - Gitter
ContainerImage is suppose to have a method fromDockerImageAsset , but that ... SmidStagingEcsStack failed: InvalidParameterException: Invalid parameter at ...
Read more >No space left on device when pulling docker image from AWS
The issue was with the EC2 instance not having enough EBS storage assigned to it. Following these steps will fix it: Navigate to...
Read more >Using Jenkins and Kaniko to build Docker images in AWS
This is the Docker-in-Docker problem, often solved by giving the container privileged access to the host, which isn't possible in Fargate. The ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After speaking with @madeline-k about this issue, the recommendation was to add the following to the
cdk.json
file:"@aws-cdk/core:newStyleStackSynthesis": true
This resulted in getting around the issue above. However there is now a new issue:
There is no parameter to allow specifying the tag or repo name, just the tarball path locally: https://docs.aws.amazon.com/cdk/api/latest/python/aws_cdk.aws_ecr_assets/TarballImageAsset.html
I am also seeing the issue above with version
1.116.0
and1.117.0
ofaws_cdk.aws_ecr_assets
when trying to create the ECR repository from a Tarball using theTarballImageAsset
construct: