Aws-cdk: appsync - apiKeyConfig expires outputting incorrect format

Created on 23 Jun 2020  路  2Comments  路  Source: aws/aws-cdk

When specifying the attribute "expires" for apiKeyConfig, the rendered cloudformation gets a value of null.

Reproduction Steps

const api = new GraphQLApi(this, 'api', {
            name: getResourceName('graphql'),
            authorizationConfig: {
                defaultAuthorization: {
                    authorizationType: AuthorizationType.API_KEY,
                    apiKeyConfig: {
                        name: "api-key",
                        description: "api-key",
                        expires: "1614164998"
                    }
                },    
            schemaDefinitionFile: 'schema.graphql',
        });

Error Log

Synth gives:

 apiapikeyApiKeyXXXXXX:
    Type: AWS::AppSync::ApiKey
    Properties:
      ApiId:
        Fn::GetAtt:
          - apiCXXXXXX
          - ApiId
      Description: api-key
      Expires: null

Environment

  • CLI Version : 1.46.0
  • Framework Version: 1.46.0
  • Node.js Version: v12.16.1
  • OS : OSX
  • Language (Version): 3.8.3

Other


This is :bug: Bug Report

@aws-cdaws-appsync bug efforsmall in-progress p2

Most helpful comment

What about using kind of Expires?

AS-IS

{
  ...,
  expires: '2020-12-31T23:30:00Z'
}

TO-BE

  • expires: Expires.atDate(new Date('2020-12-31T23:30:00Z'))
  • expires: Expires.after(cdk.Duration.months(6))
  • expires: Expires.fromTimestamp(1614164998000)
  • expires: Expires.fromString('2020-12-31T23:30:00Z')

References

I hope the things below would be promoted to @aws-cdk/core, as well as Duration

@nija-at @jogold

Expires

https://github.com/aws/aws-cdk/blob/254556d875f9a378ac98d5c3193306250068d3c9/packages/%40aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts#L318-L344

Schedule

https://github.com/aws/aws-cdk/blob/254556d875f9a378ac98d5c3193306250068d3c9/packages/%40aws-cdk/aws-applicationautoscaling/lib/schedule.ts#L3-L64

All 2 comments

According to the definition:

export interface ApiKeyConfig {
  ...

  /**
   * The time from creation time after which the API key expires, using RFC3339 representation.
   * It must be a minimum of 1 day and a maximum of 365 days from date of creation.
   * Rounded down to the nearest hour.
   * @default - 7 days from creation time
   */
  readonly expires?: string;
}

Workaround

You should set expires like 2020-12-31T23:30:00Z

Use new Date(...).toISOString() or any other date/time library.

Proposed solution

But in fact, it is also prone to errors and needs to be changed in a different way.

export interface ApiKeyConfig {
  ...

  /**
   * The duration from creation time after which the API key expires.
   * It must be a minimum of 1 day and a maximum of 365 days from date of creation.
   * Rounded down to the nearest hour.
   * @default - cdk.Duration.days(7)
   */
  readonly expiresAfter?: cdk.Duration;
}

Any good idea?

What about using kind of Expires?

AS-IS

{
  ...,
  expires: '2020-12-31T23:30:00Z'
}

TO-BE

  • expires: Expires.atDate(new Date('2020-12-31T23:30:00Z'))
  • expires: Expires.after(cdk.Duration.months(6))
  • expires: Expires.fromTimestamp(1614164998000)
  • expires: Expires.fromString('2020-12-31T23:30:00Z')

References

I hope the things below would be promoted to @aws-cdk/core, as well as Duration

@nija-at @jogold

Expires

https://github.com/aws/aws-cdk/blob/254556d875f9a378ac98d5c3193306250068d3c9/packages/%40aws-cdk/aws-s3-deployment/lib/bucket-deployment.ts#L318-L344

Schedule

https://github.com/aws/aws-cdk/blob/254556d875f9a378ac98d5c3193306250068d3c9/packages/%40aws-cdk/aws-applicationautoscaling/lib/schedule.ts#L3-L64

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mirazmamun picture mirazmamun  路  3Comments

EduardTheThird picture EduardTheThird  路  3Comments

eladb picture eladb  路  3Comments

peterdeme picture peterdeme  路  3Comments

v-do picture v-do  路  3Comments