Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public makeAppSyncApiKey() {
const oneWeekFromNowInSeconds = 60 /* s */ * 60 /* m */ * 24 /* h */ * 7 /* d */
const nowEpochTime = Math.floor(Date.now() / 1000)
return new AppSync.ApiKey({
ApiId: Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
Expires: Fn.If(
ResourceConstants.CONDITIONS.APIKeyExpirationEpochIsPositive,
Fn.Ref(ResourceConstants.PARAMETERS.APIKeyExpirationEpoch),
nowEpochTime + oneWeekFromNowInSeconds
),
}).condition(ResourceConstants.CONDITIONS.ShouldCreateAPIKey)
}
role = (name: string, region: string): any => {
return new IAM.Role({
RoleName: Fn.If(
ResourceConstants.CONDITIONS.HasEnvironmentParameter,
Fn.Join('-', [
FunctionResourceIDs.FunctionIAMRoleName(name, true), // max of 64. 64-10-26-28 = 0
Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'), // 26
Fn.Ref(ResourceConstants.PARAMETERS.Env), // 10
]),
Fn.Join('-', [
FunctionResourceIDs.FunctionIAMRoleName(name, false), // max of 64. 64-26-38 = 0
Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'), // 26
])
),
AssumeRolePolicyDocument: {
Version: '2012-10-17',
Statement: [
{
Effect: 'Allow',
private joinWithEnv(separator: string, listToJoin: any[]) {
return Fn.If(
ResourceConstants.CONDITIONS.HasEnvironmentParameter,
Fn.Join(separator, [...listToJoin, Fn.Ref(ResourceConstants.PARAMETERS.Env)]),
Fn.Join(separator, listToJoin)
);
}
private dynamoDBTableName(typeName: string): IntrinsicFunction {
return Fn.If(
ResourceConstants.CONDITIONS.HasEnvironmentParameter,
Fn.Join('-', [
typeName,
Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId'),
Fn.Ref(ResourceConstants.PARAMETERS.Env),
]),
Fn.Join('-', [typeName, Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId')])
);
}
public makeAppSyncAPI() {
return new AppSync.GraphQLApi({
Name: Fn.If(
ResourceConstants.CONDITIONS.HasEnvironmentParameter,
Fn.Join('-', [Fn.Ref(ResourceConstants.PARAMETERS.AppSyncApiName), Fn.Ref(ResourceConstants.PARAMETERS.Env)]),
Fn.Ref(ResourceConstants.PARAMETERS.AppSyncApiName)
),
AuthenticationType: 'API_KEY',
});
}
private domainName() {
return Fn.If(
ResourceConstants.CONDITIONS.HasEnvironmentParameter,
Refs.NoValue,
Fn.Join(
'-',
[
'd',
Fn.GetAtt(ResourceConstants.RESOURCES.GraphQLAPILogicalID, 'ApiId')
]
)
)
}
private joinWithEnv(separator: string, listToJoin: any[]) {
return Fn.If(
ResourceConstants.CONDITIONS.HasEnvironmentParameter,
Fn.Join(
separator,
[
...listToJoin,
Fn.Ref(ResourceConstants.PARAMETERS.Env)
]
),
Fn.Join(
separator,
listToJoin
)
)
}
export function syncLambdaArnResource({ name, region }: { name: string; region?: string }) {
const env = 'env;';
const substitutions = {};
if (referencesEnv(name)) {
substitutions[env] = Fn.Ref(ResourceConstants.PARAMETERS.Env);
}
return Fn.If(
ResourceConstants.CONDITIONS.HasEnvironmentParameter,
Fn.Sub(lambdaArnKey(name, region), substitutions),
Fn.Sub(lambdaArnKey(removeEnvReference(name), region), {})
);
}
export function lambdaArnKey(name: string, region?: string) {