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.

Creating IAM user with access key

See original GitHub issue

I’m trying to create a user with an access key along the following lines:

import iam = require('@aws-cdk/aws-iam')

const myUserName = 'my-user-name'
const user = new iam.User(this, 'myUser', {
  userName: userName
})
const accessKey = new iam.CfnAccessKey(this, 'myAccessKey', {
  userName: myUserName
})

new cdk.Output(this, 'accessKeyId', { value: accessKey.accessKeyId });
new cdk.Output(this, 'secretAccessKey', { value: accessKey.accessKeySecretAccessKey });

This works OK when I run it in two stages so that the user gets created in the first deployment and the access key gets created in the second deployment. However, if it’s run in a single stage it looks like the creation of the access key does not wait for the user to be created and thus an error occurs.

Is there a way to express the dependency of the access key resource on the user resource?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:5
  • Comments:10 (7 by maintainers)

github_iconTop GitHub Comments

42reactions
freakingawesomecommented, Aug 23, 2019

The syntax mentioned above (cdk.Output) is out of date. To achieve the same thing now you would use:

new cdk.CfnOutput(this, 'accessKeyId', { value: accessKey.ref });
new cdk.CfnOutput(this, 'secretAccessKey', { value: accessKey.attrSecretAccessKey });
13reactions
skinny85commented, Jan 25, 2019

Hey @floehopper,

can you try:

const accessKey = new CfnAccessKey(this, 'myAccessKey', {
  userName: user.userName,
});

?

Thanks, Adam

Read more comments on GitHub >

github_iconTop Results From Across the Web

create-access-key — AWS CLI 1.27.37 Command Reference
Creates a new Amazon Web Services secret access key and corresponding Amazon Web Services access key ID for the specified user. The default...
Read more >
create-access-key — AWS CLI 2.9.8 Command Reference
Creates a new Amazon Web Services secret access key and corresponding Amazon Web Services access key ID for the specified user. The default...
Read more >
How to create IAM User Access Keys via AWS CLI
To create programmatic Access Keys for an AWS IAM User using AWS CLI, run the command aws iam create-access-key . On the command...
Read more >
Step-by-step guide on how to create an IAM user in AWS
Select the Users menu. Navigate to the Users screen. You'll find it in the IAM dashboard, under the Identity and Access Management (IAM)...
Read more >
AWS Access Key IAM Permissions and IAM Policies
Create IAM user for FortiSIEM monitoring · Login to the IAM Console - Users Tab. · Click Create Users. · Type in a...
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