Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aws-lambda-secretsmanager #162

Merged

Conversation

allen-moheimani-aws
Copy link
Contributor

@allen-moheimani-aws allen-moheimani-aws commented Apr 23, 2021

Issue #, if available: #76

Description of changes:
Implemented aws-lambda-secretsmanger construct

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

allen-moheimani-aws and others added 17 commits March 24, 2021 15:57
feat(aws-lambda-secretsmanager): Create core helpers to provision secrets manager secret.
…m/aws-solutions-constructs into allen/aws-lambda-secrets-manager
@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: codebuildgithubautobuildPro-fkVQbXRiQi6A
  • Commit ID: 9ae1aec
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@hnishar hnishar linked an issue Apr 23, 2021 that may be closed by this pull request
2 tasks
Copy link
Contributor

@biffgaut biffgaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the whole this looks really good. A couple things that nibble around the edges.

For the integration tests - how did you generate your .expected files? They should be generated using cdk-integ, which will actually deploy the stack and grab the template. We weren't clear enough about this earlier and some contributors hand edited files and had integ tests that didn't deploy. Please confirm that yours are cdk-integ generated.

* @param {cdk.App} scope - represents the scope for all the resources.
* @param {string} id - this is a a scope-unique id.
* @param {LambdaToSecretsmanagerProps} props - user provided props for the construct.
* @since 1.49.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will probably be 1.100.0 or 1.101.0 (depending upon how fast these reviews go). I'm going to ask the team about cutting this line entirely from now on - I don't want to have to come back an edit it when we know what release contains this PR.

enableDnsSupport: true,
},
});
defaults.AddAwsServiceEndpoint(stack, vpc, defaults.ServiceEndpointTypes.SECRETS_MANAGER);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test should not add the ServiceEndpoint - it should test that the construct adds a service endpoint to the existing VPC.

removalPolicy: RemovalPolicy.DESTROY,
});
// Assertion 1
expect(SynthUtils.toCloudFormation(stack)).toMatchSnapshot();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only use snapshot for 1 test (probably all defaults) - for the rest just use the inspection functions to check the specific target of the test. (My first construct I used snapshots everywhere, Hitendra suggested not to do that because refreshing snapshots can be onerous - in the time since then I have learned exactly what he means. :-) )

handler: "index.handler",
code: lambda.Code.fromAsset(`${__dirname}/lambda`),
},
existingVpc: vpc
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For integration tests, include secretProps with removalPolicy of DESTROY any time the integration test is creating a secret - otherwise every time we refresh all the integration tests we leave a bunch of secrets behind when we clean up.

existingSecretObj: secret
});
// Assertion 1
expect(SynthUtils.toCloudFormation(stack)).toMatchSnapshot();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Only use the snapshot on the default deployment - use inspection functions for other tests.

* or in the 'license' file accompanying this file. This file is distributed on an 'AS IS' BASIS, WITHOUT WARRANTIES
* OR CONDITIONS OF ANY KIND, express or implied. See the License for the specific language governing permissions
* and limitations under the License.
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit tests that appear to be missing:

  • Existing function
  • Grant Write access

(let me know if I just missed them)

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: codebuildgithubautobuildPro-fkVQbXRiQi6A
  • Commit ID: 62cc689
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: codebuildgithubautobuildPro-fkVQbXRiQi6A
  • Commit ID: afaf9a3
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: codebuildgithubautobuildPro-fkVQbXRiQi6A
  • Commit ID: 8e66733
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: codebuildgithubautobuildPro-fkVQbXRiQi6A
  • Commit ID: 5dff62f
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: codebuildgithubautobuildPro-fkVQbXRiQi6A
  • Commit ID: 658710d
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

const secret = new Secret(stack, 'secret', {});
new LambdaToSecretsmanager(stack, 'lambda-to-secretsmanager-stack', {
const existingSecret = new Secret(stack, 'secret', {});
const pattern = new LambdaToSecretsmanager(stack, 'lambda-to-secretsmanager-stack', {
lambdaFunctionProps: {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

secretProps: { removalPolicy: RemovalPolicy.DESTROY } ?

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: codebuildgithubautobuildPro-fkVQbXRiQi6A
  • Commit ID: 38ad126
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: codebuildgithubautobuildPro-fkVQbXRiQi6A
  • Commit ID: 0170268
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: codebuildgithubautobuildPro-fkVQbXRiQi6A
  • Commit ID: 546f6d0
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: codebuildgithubautobuildPro-fkVQbXRiQi6A
  • Commit ID: b8033aa
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

Copy link
Contributor

@hnishar hnishar left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a unit test for using CMK to encrypt the secret, rest all looks good!

@@ -0,0 +1,387 @@
/**
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Request to add a unit test case for overriding readonly secretProps?: secretsmanager.SecretProps; the most common use case I can think of is passing in CMK SecretProps.encryptionKey to be used instead of the default aws/secretsmanager key for secret encryption

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated thanks @hnishar !

…ecretProps and validate the KMS key permissions.
…m/aws-solutions-constructs into allen/aws-lambda-secrets-manager
@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: codebuildgithubautobuildPro-fkVQbXRiQi6A
  • Commit ID: 3dce4c4
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-solutions-constructs-team
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: codebuildgithubautobuildPro-fkVQbXRiQi6A
  • Commit ID: 4e56276
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@hnishar hnishar merged commit ac9251c into awslabs:main May 6, 2021
@msmjack
Copy link

msmjack commented May 6, 2021

This is now the most important solutions construct! I'm so happy! Shared it with a bunch of people. 💯 🥇 👍 You rock! Be encouraged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New pattern: aws-lambda-secretsmanager
7 participants