aws / aws-cdk

The AWS Cloud Development Kit is a framework for defining cloud infrastructure in code
https://aws.amazon.com/cdk
Apache License 2.0
11.41k stars 3.8k forks source link

(aws-lambda): Lambda shareable events #19471

Open michaelbrewer opened 2 years ago

michaelbrewer commented 2 years ago

Description

Shareable test events is now available in the Lambda console. All you need to do it is setup an Amazon EventBridge schema registry called lambda-testevent-schemas and then create schemas with examples with the following naming convention _<YOUR_FUNCTION_NAME>-schema.

Use Case

Allows you to quickly populate shareable events on your dev, test and stage environments

Proposed Solution

From a UX point of view, we could simply things by just asking for the sample events you want to add ie:

function.add_shareable_test_event("test_pass", test_pass_event)
function.add_shareable_test_event("test_fail", test_fail_event)

And to be future proof also allow for a full schema definition.

This would use a CloudFormation Custom resource under the schemas to setup these test events (as well as ensure the required registry is created). In the future, hopefully official CloudFormation support will be coming.

A prototype for this exists here: Lambda shareable test events

Other information

Acknowledge

kaizencc commented 2 years ago

Marking this as p2 for now, which means it is not in our immediate roadmap, until I see that enough people are searching for this feature. The workaround is to use a custom resource to do this for now.

madeline-k commented 1 year ago

Issue for tracking cloudformation support of this feature: https://github.com/aws-cloudformation/cloudformation-coverage-roadmap/issues/1215

relm923 commented 1 month ago

The schema part is doable with CfnSchema. Still need a custom resource to ensure the registry exists

new eventSchemas.CfnSchema(scope, 'TestEventSchema', {
  content: JSON.stringify({
    components: {
      examples: {
        testEventName: {
          value: {
            foo: 'bar',
          },
        },
      },
      schemas: {},
    },
    info: { title: 'Event', version: '1.0.0' },
    // eslint-disable-next-line spellcheck/spell-checker
    openapi: '3.0.0',
    paths: {},
  }),
  // eslint-disable-next-line spellcheck/spell-checker
  registryName: 'lambda-testevent-schemas',
  schemaName: `_${lambda.functionName}-schema`,
  type: 'OpenApi3',
});