aws-amplify / aws-amplify/amplify-cli
Deployment of custom CDK resource containing AWS Step Function fails
- Dominant language
- TypeScript
- Stars
- 2.9k
- Forks
- 825
- Avg merge
- 11d 23h
- Merged PRs (30d)
- 2
Description
### Before opening, please confirm:
- [X] I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
- [X] I have [searched for duplicate or closed issues](https://github.com/aws-amplify/amplify-cli/issues?q=is%3Aissue+).
- [X] I have read the guide for [submitting bug reports](https://github.com/aws-amplify/amplify-cli/blob/master/CONTRIBUTING.md#bug-reports).
- [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
- [X] I have removed any sensitive information from my code snippets and submission.
### How did you install the Amplify CLI?
npm
### If applicable, what version of Node.js are you using?
v17.8.0
### Amplify CLI Version
8.0.3
### What operating system are you using?
Mac
### Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
No manual changes made
### Amplify Categories
custom
### Amplify Commands
push
### Describe the bug
When adding a Step Function resource to a CDK stack generated by `amplify add custom` (and updating the CDK dependencies of the stack to the latest `1.153.1`), the following error comes up during `amplify deploy`:
`CREATE_FAILED customcustomResource73fbfaba AWS::CloudFormation::Stack Wed Apr 27 2022 22:14:08 GMT+0200 (Central European Summer Time) Template error: Mapping named 'ServiceprincipalMap' is not present in the 'Mappings' section of template.`
### Expected behavior
Step Function resource should be deployed.
### Reproduction steps
1. `amplify init`.
2. `amplify add custom`.
3. Update CDK dependencies of the custom resource to latest CDK v1 version (`1.153.1`) by changing `package.json` to:
```
{
"name": "custom-resource",
"version": "1.0.0",
"description": "",
"scripts": {
"build": "tsc",
"watch": "tsc -w",
"test": "echo \"Error: no test specified\" && exit 1"
},
"dependencies": {
"@aws-amplify/cli-extensibility-helper": "^2.0.0",
"@aws-cdk/core": "~1.153.1",
"@aws-cdk/aws-stepfunctions": "~1.153.1"
},
"devDependencies": {
"typescript": "^4.2.4"
}
}
```
and running `npm install`.
4. Insert minimal AWS Step Function in the CDK stack by updating `cdk-stack.ts` to:
```
import * as cdk from "@aws-cdk/core";
import * as AmplifyHelpers from "@aws-amplify/cli-extensibility-helper";
import * as sfn from "@aws-cdk/aws-stepfunctions";
export class cdkStack extends cdk.Stack {
constructor(
scope: cdk.Construct,
id: string,
props?: cdk.StackProps,
amplifyResourceProps?: AmplifyHelpers.AmplifyResourceProps
) {
super(scope, id, props);
/* Do not remove - Amplify CLI automatically injects the current deployment environment in this input parameter */
new cdk.CfnParameter(this, "env", {
type: "String",
description: "Current Amplify CLI env name",
});
const startState = new sfn.Pass(this, "StartState");
const exampleSfn = new sfn.StateMachine(this, "StateMachine", {
definition: startState,
});
}
}
```
6. Run `amplify deploy` and confirm deployment to produce error.
### GraphQL schema(s)
_No response_
### Log output
_No response_
### Additional information
The CDK stack above deploys without issue ouside of Amplify with CDK v1 and v2.
The CDK stack above also deploys without issue with CDK v1 versions `1.124.0` and `1.128.0` (but not the latest version `1.153.1`) as an amplify custom resource.
The stack also deploys if we add an IAM role to the Step Function which should not be necessary according to the CDK docs (and is not necessary when using the other CDK versions mentioned above):
```
import * as cdk from "@aws-cdk/core";
import * as AmplifyHelpers from "@aws-amplify/cli-extensibility-helper";
import * as sfn from "@aws-cdk/aws-stepfunctions";
import * as iam from "@aws-cdk/aws-iam";
export class cdkStack extends cdk.Stack {
constructor(
scope: cdk.Construct,
id: string,
props?: cdk.StackProps,
amplifyResourceProps?: AmplifyHelpers.AmplifyResourceProps
) {
super(scope, id, props);
/* Do not remove - Amplify CLI automatically injects the current deployment environment in this input parameter */
new cdk.CfnParameter(this, "env", {
type: "String",
description: "Current Amplify CLI env name",
});
const serviceRole = new iam.Role(this, "Role", {
assumedBy: new iam.ServicePrincipal("states.eu-west-1.amazonaws.com"),
});
const startState = new sfn.Pass(this, "StartState");
const exampleSfn = new sfn.StateMachine(this, "StateMachine", {
definition: startState,
role: serviceRole,
});
}
}
```
Contributor guide
Assessment
This issue has not been assessed yet.