gpt4 book ai didi

amazon-web-services - 如何在 AWS CloudFormationTemplate 中引用 Lambda 的 AWS GlobalSecondaryIndex 名称

转载 作者:行者123 更新时间:2023-12-03 07:24:32 24 4
gpt4 key购买 nike

我正在尝试编写一个云形成模板,其中 DynamoDBTable 的全局二级索引 (GSI) 名称可用作 AWS Lambda 中的环境变量。我有下面的模板,但无法获取对 AWS Lambda 中的 GSI 名称的引用(模板中的最后一行)。

预先感谢您的帮助。

# The AWSTemplateFormatVersion identifies the capabilities of the template
# https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/format-version-structure.html
AWSTemplateFormatVersion: 2010-09-09
Description: >-
temp

Parameters:
Environment:
Type: String
Description: The name of the stage, e.g. "dev", "preprod", "prod"
Default: ravi

Transform:
- AWS::Serverless-2016-10-31

Resources:
customerLambdaDLQ:
Type: AWS::SQS::Queue
Properties:
QueueName: !Sub "${Environment}-customer-lambda-dead-letter-queue"
projectionsLambdaRole:
Type: "AWS::IAM::Role"
Properties:
AssumeRolePolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Principal:
Service:
- lambda.amazonaws.com
Action:
- "sts:AssumeRole"
Path: /
Policies:
- PolicyName: !Sub "${Environment}-customer-lambda-role"
PolicyDocument:
Version: 2012-10-17
Statement:
- Effect: Allow
Action:
- "sqs:SendMessage*"
- "dynamodb:GetItem"
- "dynamodb:DeleteItem"
- "dynamodb:PutItem"
- "dynamodb:Scan"
- "dynamodb:Query"
- "dynamodb:UpdateItem"
- "dynamodb:BatchWriteItem"
- "dynamodb:BatchGetItem"
- "dynamodb:DescribeTable"
- "dynamodb:ConditionCheckItem"
- "dynamodb:DescribeStream"
- "dynamodb:GetRecords"
- "dynamodb:GetShardIterator"
- "dynamodb:ListStreams"
Resource:
- !GetAtt customerLambdaDLQ.Arn
customerTable:
Type: AWS::DynamoDB::Table
Properties:
TableName: !Sub "${Environment}-customer-table"
AttributeDefinitions:
- AttributeName: PK
AttributeType: S
- AttributeName: SK
AttributeType: S
- AttributeName: indexKey_1
AttributeType: S
- AttributeName: indexKey_2
AttributeType: S
- AttributeName: customerId
AttributeType: S
KeySchema:
- AttributeName: PK
KeyType: HASH
- AttributeName: SK
KeyType: RANGE
GlobalSecondaryIndexes:
- IndexName: customer-index-1
KeySchema:
- AttributeName: indexKey_1
KeyType: HASH
- AttributeName: indexKey_2
KeyType: RANGE
Projection:
ProjectionType: ALL
- IndexName: customer-index-2
KeySchema:
- AttributeName: customerId
KeyType: HASH
- AttributeName: indexKey_2
KeyType: RANGE
Projection:
NonKeyAttributes:
- first_name
- last_name
- city
- state
- country
ProjectionType: INCLUDE
BillingMode: PAY_PER_REQUEST
SSESpecification:
SSEEnabled: true
primer:
Type: AWS::Lambda::Function
Properties:
Runtime: nodejs12.x
Role: !GetAtt projectionsLambdaRole.Arn
Handler: index.handler
Code:
ZipFile: |
var aws = require('aws-sdk')
var response = require('cfn-response')
exports.handler = function(event, context) {
console.log("REQUEST RECEIVED:\n" + JSON.stringify(event))
// For Delete requests, immediately send a SUCCESS response.
if (event.RequestType == "Delete") {
response.send(event, context, "SUCCESS")
return
}
var responseStatus = "FAILED"
var responseData = {}
var functionName = event.ResourceProperties.FunctionName
var lambda = new aws.Lambda()
lambda.invoke({ FunctionName: functionName }, function(err, invokeResult) {
if (err) {
responseData = {Error: "Invoke call failed"}
console.log(responseData.Error + ":\n", err)
}
else responseStatus = "SUCCESS"
response.send(event, context, responseStatus, responseData)
})
}
Description: Invoke a function during stack creation.
Environment:
Variables:
TABLE_NAME: !Ref customerTable
GSI_1_NAME: !GetAtt customerTable.GlobalSecondaryIndexes.customer-index-1

最佳答案

GSI 正是您所命名的,因此您只需传入 customer-index-1

关于amazon-web-services - 如何在 AWS CloudFormationTemplate 中引用 Lambda 的 AWS GlobalSecondaryIndex 名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60244709/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com