question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

(aws-cdk/aws-ecs): Unable to construct ContainerImage from tarball.

See original GitHub issue

When 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

  1. Follow this tutorial: https://docs.aws.amazon.com/AmazonECS/latest/developerguide/tutorial-ecs-web-server-cdk.html
  2. 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
    });
  }
}
  1. Create tar of docker image. I used docker save alpine/git -o lib/alpine.tar.
  2. 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:closed
  • Created 2 years ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
noyceguycommented, Aug 10, 2021

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:

dev-ecr: deploying...
[0%] start: Publishing a5db53e3b8dae8f8883cff52afdabab4ef0136974e3f57da3d2a535f321f5573:current_account-current_region
[50%] success: Published a5db53e3b8dae8f8883cff52afdabab4ef0136974e3f57da3d2a535f321f5573:current_account-current_region
[50%] start: Publishing 109ebcea6be849424630835f0f7c4c1fab51742f4a9037b2cacffdad8a624761:current_account-current_region
Error parsing reference: "" is not a valid repository/tag: invalid reference format
[100%] fail: docker tag  xxxxxxxx.dkr.ecr.eu-central-1.amazonaws.com/cdk-hnb659fds-container-assets-xxxxxx-eu-central-1:109ebcea6be849424630835f0f7c4c1fab51742f4a9037b2cacffdad8a624761 exited with error code 1: Error parsing reference: "" is not a valid repository/tag: invalid reference format

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

1reaction
noyceguycommented, Aug 10, 2021

I am also seeing the issue above with version 1.116.0 and 1.117.0 of aws_cdk.aws_ecr_assets when trying to create the ECR repository from a Tarball using the TarballImageAsset construct:

jsii.errors.JavaScriptError: 
  Error: LegacyStackSynthesizer does not support this type of file asset: {"sourceHash":"95c924c84f5d023be4edee540cb2cb401a49f115d01ed403b288f6cb412771df","executable":["sh","-c","docker load -i asset.95c924c84f5d023be4edee540cb2cb401a49f115d01ed403b288f6cb412771df.tar | sed \"s/Loaded image: //g\""]}
      at LegacyStackSynthesizer.doAddDockerImageAsset (/private/var/folders/kr/_7s2bxtx56l7xdrmpygsm9s8b18z49/T/jsii-kernel-8aaq91/node_modules/@aws-cdk/core/lib/stack-synthesizers/legacy.js:137:23)
      at LegacyStackSynthesizer.addDockerImageAsset (/private/var/folders/kr/_7s2bxtx56l7xdrmpygsm9s8b18z49/T/jsii-kernel-8aaq91/node_modules/@aws-cdk/core/lib/stack-synthesizers/legacy.js:105:25)
      at Stack.addDockerImageAsset (/private/var/folders/kr/_7s2bxtx56l7xdrmpygsm9s8b18z49/T/jsii-kernel-8aaq91/node_modules/@aws-cdk/core/lib/stack.js:434:33)
      at LegacyStackSynthesizer.addDockerImageAsset (/private/var/folders/kr/_7s2bxtx56l7xdrmpygsm9s8b18z49/T/jsii-kernel-8aaq91/node_modules/@aws-cdk/core/lib/stack-synthesizers/legacy.js:109:31)
      at new TarballImageAsset (/private/var/folders/kr/_7s2bxtx56l7xdrmpygsm9s8b18z49/T/jsii-kernel-8aaq91/node_modules/@aws-cdk/aws-ecr-assets/lib/tarball-asset.js:35:44)
      at /private/var/folders/kr/_7s2bxtx56l7xdrmpygsm9s8b18z49/T/tmpj_a2b69i/lib/program.js:8154:58
      at Kernel._wrapSandboxCode (/private/var/folders/kr/_7s2bxtx56l7xdrmpygsm9s8b18z49/T/tmpj_a2b69i/lib/program.js:8582:24)
      at Kernel._create (/private/var/folders/kr/_7s2bxtx56l7xdrmpygsm9s8b18z49/T/tmpj_a2b69i/lib/program.js:8154:34)
      at Kernel.create (/private/var/folders/kr/_7s2bxtx56l7xdrmpygsm9s8b18z49/T/tmpj_a2b69i/lib/program.js:7895:29)
      at KernelHost.processRequest (/private/var/folders/kr/_7s2bxtx56l7xdrmpygsm9s8b18z49/T/tmpj_a2b69i/lib/program.js:9479:36)
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found