aws / aws/aws-cdk

AppSync: JS Resolvers do not support code bundled in custom bundling environment

Open
#24,548 4 comments 3 reactions 0 assignees View on GitHub
@aws-cdk/aws-appsync bug effort/medium p2
Dominant language
TypeScript
Stars
12.9k
Forks
4.6k
Avg merge
2d 3h
Merged PRs (30d)
83

Description

### Describe the bug

`AppSync` now supports `JavaScript` resolvers which in `CDK` are can be populated trough the `code` prop which can either be `fromInline` or `fromAsset`.

The problem is that it seems `AppSync` can only take `.js` and will throw a `The code contains one or more errors.` exception when you use a custom bundling environment, since this emits a `.zip`.

### Expected Behavior

`AppSync` digests single file archives generated when using a custom `Docker` environment to bundle `JavaScript` `AppSync` resolvers.

### Current Behavior

`AppSync` throws a 'The code contains one or more errors.' exception when using a custom `Docker` environment to bundle `JavaScript` `AppSync` resolvers.

### Reproduction Steps

```ts
new Resolver(this, "TestResolver", {
api: new GraphqlApi(this, "TestApi", {
name: "TestApi",
schema: SchemaFile.fromAsset(path.join(__dirname, "./schema.graphql")),
}),
typeName: "Query",
fieldName: "test",
runtime: FunctionRuntime.JS_1_0_0,
code: Code.fromAsset(path.join(__dirname, "./"), {
bundling: {
image: DockerImage.fromBuild(path.join(__dirname, "./")),
command: [
"esbuild",
"/asset-input/resolver.ts",
"--target=node18",
"--outfile=/asset-output/index.js",
],
},
}),
});
```

### Possible Solution

I see two possible solution for this problem:

1. Allow single file outputs from bundling with custom environment rather then only archives
2. Somehow make AppSync phrase the archive edited from a custom environment bundle

### Additional Information/Context

_No response_

### CDK CLI Version

2.67.0

### Framework Version

_No response_

### Node.js Version

18

### OS

aws/codebuild/amazonlinux2-x86_64-standard:4.0

### Language

Typescript

### Language Version

_No response_

### Other information

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the issue with the TypeScript Resolver and Code.fromAsset example, using the custom Docker bundling command that writes index.js to /asset-output. Trace how the bundled asset is passed to the AppSync JavaScript resolver and verify whether single-file archives are accepted. Done means the reproduced resolver deploys successfully without the code validation error.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, docker, javascript, typescript
Domain
api, build-system, cloud
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.